更新数据库的共通类
package updateCommon;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class CommonUpdate {
/**
* author: YSM
* <p>Title: update</p>
* <p>Description: 更新数据库表,共通方法</p>
* @param updateMap 需要更新的字段
* @param qualificationMap 更新条件
* @param tableName 更新的表名
*/
public static void update(Map<String, String> updateMap, Map<String, String> qualificationMap, String tableName) {
Set<String> updateSet = updateMap.keySet();
Iterator<String> updateIt = updateSet.iterator();
String updateKey = null;
StringBuffer updateSql = new StringBuffer("");
while (updateIt.hasNext()) {
updateKey = updateIt.next();
String[] tempStr = dealKeyAndValueByDataType(updateKey, updateMap);
updateSql.append(tempStr[0]);
updateSql.append(" = ");
updateSql.append(tempStr[1]);
if (updateIt.hasNext()) {
updateSql.append(" , ");
}
}
Set<String> qualificationSet = qualificationMap.keySet();
Iterator<String> qualificationIt = qualificationSet.iterator();
StringBuffer qualificationSql = new StringBuffer("");
String qualificationKey = null;
if (qualificationIt.hasNext()) {
qualificationSql.append(" where ");
}
while (qualificationIt.hasNext()) {
qualificationKey = qualificationIt.next();
String[] tempStr = dealKeyAndValueByDataType(qualificationKey, qualificationMap);
qualificationSql.append(tempStr[0]);
qualificationSql.append(" = ");
qualificationSql.append(tempStr[1]);
if (qualificationIt.hasNext()) {
qualificationSql.append(" and ");
}
}
String sql = "update " + tableName + " set " + updateSql + qualificationSql;
System.out.println(sql);
}
private static String[] dealKeyAndValueByDataType(String str, Map<String, String> qualificationMap) {
String [] tempStr = str.split("_");
String [] returnStr = new String[2];
returnStr[0] = tempStr[1];
if ("char".equals(tempStr[0])) {
returnStr[1] = "'" + (String)qualificationMap.get(str) + "'";
} else if ("int".equals(tempStr[0])) {
returnStr[1] = (String) qualificationMap.get(str);
}
return returnStr;
}
public static void main (String [] args) {
Map<String, String> updateMap = new HashMap<String, String>();
updateMap.put("int_id", "1");
updateMap.put("char_name", "ysm");
Map<String, String> qualificationMap = new HashMap<String, String>();
qualificationMap.put("int_sn", "4");
qualificationMap.put("char_osn", "12345abc");
update(updateMap, qualificationMap, "t_repair");
}
}
1 楼 cin_ie 2010-08-07 package chartOption.bl;
import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.io.FileOutputStream;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
public class CakyChart {
private static final String CHART_PATH = "D:/test/";
/**
* <p>
* Title: main
* </p>
* <p>
* Description:
* </p>
*
* @param args
*/
public static void main(String[] args) {
CakyChart cakyChart = new CakyChart();
double[] data = { 2, 2 };
String[] keys = { "大饼1", "大饼2"};
cakyChart.makePieChart(data, keys);
}
// 饼状图 数据集
public PieDataset getDataPieSetByUtil(double[] data,
String[] datadescription) {
if (data != null && datadescription != null) {
if (data.length == datadescription.length) {
DefaultPieDataset dataset = new DefaultPieDataset();
for (int i = 0; i < data.length; i++) {
dataset.setValue(datadescription[i], data[i]);
}
return dataset;
}
}
return null;
}
public void makePieChart(double[] data, String[] keys) {
System.out.println("flag_1");
this.createValidityComparePimChar(getDataPieSetByUtil(data, keys), "彩色大饼", "pie2.png", keys);
} 2 楼 cin_ie 2010-08-07 /**
* 饼状图
*
* @param dataset
* 数据集
* @param chartTitle
* 图标题
* @param charName
* 生成图的名字
* @param pieKeys
* 分饼的名字集
* @return
*/
public String createValidityComparePimChar(PieDataset dataset,
String chartTitle, String charName, String[] pieKeys) {
System.out.println("flag_2");
JFreeChart chart = ChartFactory.createPieChart3D(chartTitle, dataset, true, true, false);
// JFreeChart chart = ChartFactory.createPieChart(chartTitle, dataset, true, true, false);
System.out.println("flag_2.1");
chart.setAntiAlias(false);
// 图片背景色
chart.setBackgroundPaint(Color.white);
// 设置图标题的字体重新设置title
Font font = new Font("隶书", Font.BOLD, 25);
TextTitle title = new TextTitle(chartTitle);
title.setFont(font);
chart.setTitle(title);
System.out.println("flag_3");
PiePlot3D plot = (PiePlot3D) chart.getPlot();
// 图片中显示百分比:默认方式
// 指定饼图轮廓线的颜色
// plot.setBaseSectionOutlinePaint(Color.BLACK);
// plot.setBaseSectionPaint(Color.BLACK);
// 设置无数据时的信息
plot.setNoDataMessage("无对应的数据,请重新查询。");
// 设置无数据时的信息显示颜色
plot.setNoDataMessagePaint(Color.red);
// 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位
plot.setLabelGenerator(new StandardPieSectionLabelGenerator(
"{0}={1}({2})", NumberFormat.getNumberInstance(),
new DecimalFormat("0.00%")));
// 图例显示百分比:自定义方式, {0} 表示选项, {1} 表示数值, {2} 表示所占比例
plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(
"{0}={1}({2})"));
plot.setLabelFont(new Font("SansSerif", Font.TRUETYPE_FONT, 12));
3 楼 cin_ie 2010-08-07 System.out.println("flag_4");
// 指定图片的透明度(0.0-1.0)
plot.setForegroundAlpha(0.65f);
// 指定显示的饼图上圆形(false)还椭圆形(true)
plot.setCircular(false, true);
// 设置第一个 饼块section 的开始位置,默认是12点钟方向
plot.setStartAngle(90);
// // 设置分饼颜色
plot.setSectionPaint(pieKeys[0], new Color(244, 194, 144));
plot.setSectionPaint(pieKeys[1], new Color(144, 233, 144));
FileOutputStream fos_jpg = null;
try {
// 文件夹不存在则创建
isChartPathExist(CHART_PATH);
String chartName = CHART_PATH + charName;
fos_jpg = new FileOutputStream(chartName);
// 高宽的设置影响椭圆饼图的形状
ChartUtilities.writeChartAsPNG(fos_jpg, chart, 500, 230);
return chartName;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
try {
fos_jpg.close();
System.out.println("create pie-chart.");
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* 判断文件夹是否存在,如果不存在则新建
* @param chartPath
*/
private void isChartPathExist(String chartPath) {
File file = new File(chartPath);
if (!file.exists()) {
file.mkdirs();
// log.info("CHART_PATH="+CHART_PATH+"create.");
}
}
}