SqlRowSet sqlRowSet = null;
String ls_id = "";
for (int j = 0; j < listSQL.size(); j++) {
String sql = String.valueOf(listSQL.get(j)); // 逐条获取sql语句
sqlRowSet = jdbcTemplate.queryForRowSet(sql);
SqlRowSetMetaData sqlRsmd = sqlRowSet.getMetaData();
int columnCount = sqlRsmd.getColumnCount(); // 获得表字段个数
String tableName = sqlRsmd.getTableName(columnCount); // 获得表名称
if(StringUtils.isEmpty(tableName)){
tableName = PublicUtil.getTableName(sql);
}
String tableId="";
while (sqlRowSet.next()) {
StringBuffer ColumnName = new StringBuffer();
StringBuffer ColumnValue = new StringBuffer();
for (int i = 1; i <= columnCount; i++) {
String value = sqlRowSet.getString(i);
if (value == null || "".equals(value)) {
value = "";
}
Map<String, String> fieldMap = new HashMap<String, String>();
fieldMap.put("name", sqlRsmd.getColumnName(i));
fieldMap.put("fieldType", String.valueOf(sqlRsmd.getColumnType(i)));
// 生成插入数据sql语句
if (i == 1) {
// 先生成删除指定ID语句,清除现有冲突数据
insertList.add("delete from " + tableName + " where " + sqlRsmd.getColumnName(i) + "='" + value + "';");
ColumnName.append(sqlRsmd.getColumnName(i));
ls_id = value;
tableId = value;
if (Types.CHAR == sqlRsmd.getColumnType(i) || Types.VARCHAR == sqlRsmd.getColumnType(i)) {
ColumnValue.append("'").append(value).append("',");
} else if (Types.SMALLINT == sqlRsmd.getColumnType(i) || Types.INTEGER == sqlRsmd.getColumnType(i) || Types.BIGINT == sqlRsmd.getColumnType(i) || Types.FLOAT == sqlRsmd.getColumnType(i) || Types.DOUBLE == sqlRsmd.getColumnType(i) || Types.NUMERIC == sqlRsmd.getColumnType(i) || Types.DECIMAL == sqlRsmd.getColumnType(i)) {
if ("".equals(value)) value = "0";
ColumnValue.append(value).append(",");
} else if (Types.DATE == sqlRsmd.getColumnType(i) || Types.TIME == sqlRsmd.getColumnType(i) || Types.TIMESTAMP == sqlRsmd.getColumnType(i)) {
if ("".equals(value))
value = "2000-01-01";
ColumnValue.append("'").append(value).append("',");
} else {
ColumnValue.append(value).append(",");
}
} else if (i == columnCount) {
ColumnName.append("," + sqlRsmd.getColumnName(i));
if (Types.CHAR == sqlRsmd.getColumnType(i) || Types.VARCHAR == sqlRsmd.getColumnType(i) || Types.LONGVARCHAR == sqlRsmd.getColumnType(i)) {
ColumnValue.append("'").append(value).append("'");
} else if (Types.SMALLINT == sqlRsmd.getColumnType(i) || Types.INTEGER == sqlRsmd.getColumnType(i) || Types.BIGINT == sqlRsmd.getColumnType(i) || Types.FLOAT == sqlRsmd.getColumnType(i) || Types.DOUBLE == sqlRsmd.getColumnType(i) || Types.NUMERIC == sqlRsmd.getColumnType(i) || Types.DECIMAL == sqlRsmd.getColumnType(i)) {
if ("".equals(value)) value = "0";
ColumnValue.append(value);
} else if (Types.DATE == sqlRsmd.getColumnType(i) || Types.TIME == sqlRsmd.getColumnType(i) || Types.TIMESTAMP == sqlRsmd.getColumnType(i)) {
if ("".equals(value))
value = "2000-01-01";
ColumnValue.append("'").append(value).append("'");
} else {
ColumnValue.append(value).append("");
}
} else {
ColumnName.append("," + sqlRsmd.getColumnName(i));
if (Types.CHAR == sqlRsmd.getColumnType(i) || Types.VARCHAR == sqlRsmd.getColumnType(i) || Types.LONGVARCHAR == sqlRsmd.getColumnType(i)) {
ColumnValue.append("'").append(value).append("'").append(",");
} else if (Types.SMALLINT == sqlRsmd.getColumnType(i) || Types.INTEGER == sqlRsmd.getColumnType(i) || Types.BIGINT == sqlRsmd.getColumnType(i) || Types.FLOAT == sqlRsmd.getColumnType(i) || Types.DOUBLE == sqlRsmd.getColumnType(i) || Types.NUMERIC == sqlRsmd.getColumnType(i) || Types.DECIMAL == sqlRsmd.getColumnType(i)) {
if ("".equals(value)) value = "0";
ColumnValue.append(value).append(",");
} else if (Types.DATE == sqlRsmd.getColumnType(i) || Types.TIME == sqlRsmd.getColumnType(i) || Types.TIMESTAMP == sqlRsmd.getColumnType(i)) {
if ("".equals(value))
value = "2000-01-01";
ColumnValue.append("'").append(value).append("',");
} else if (Types.BLOB == sqlRsmd.getColumnType(i) || Types.LONGVARCHAR == sqlRsmd.getColumnType(i) || Types.LONGNVARCHAR == sqlRsmd.getColumnType(i) || Types.BINARY == sqlRsmd.getColumnType(i) || Types.LONGVARBINARY == sqlRsmd.getColumnType(i) || Types.VARBINARY == sqlRsmd.getColumnType(i)) {
String ls_tmp = getBlob(ls_id, tableName, sqlRsmd.getColumnName(i), jdbcTemplate);
ColumnValue.append(ls_tmp).append(",");
} else {
ColumnValue.append(value).append(",");
}
}