根据MySQL表数据导出INSERT INTO语句的方法(三)

2014-11-24 17:13:37 · 作者: · 浏览: 2
NTEGER == rsmd.getColumnType(i)
|| Types.BIGINT == rsmd.getColumnType(i) || Types.FLOAT == rsmd.getColumnType(i)
|| Types.DOUBLE == rsmd.getColumnType(i) || Types.NUMERIC == rsmd.getColumnType(i)
|| Types.DECIMAL == rsmd.getColumnType(i)) {
if (value == null) {
ColumnValue.append("null,");
} else {
ColumnValue.append(value).append(",");
}
} else if (Types.DATE == rsmd.getColumnType(i) || Types.TIME == rsmd.getColumnType(i)
|| Types.TIMESTAMP == rsmd.getColumnType(i)) {
if (value == null) {
ColumnValue.append("null,");
} else {
ColumnValue.append("timestamp'").append(value).append("',");
}
} else {
if (value == null) {
ColumnValue.append("null,");
} else {
ColumnValue.append(value).append(",");
}
}
}
}
//System.out.println(ColumnName.toString());
//System.out.println(ColumnValue.toString());
insertSQL(ListTable.get(j).toString(), ColumnName, ColumnValue);
}
}
return rs;
}


/**
* 拼装insertsql 放到全局list里面
*
* @param ColumnName
* @param ColumnValue
*/
private static void insertSQL(String TableName, StringBuffer ColumnName,
StringBuffer ColumnValue) {
StringBuffer insertSQL = new StringBuffer();
insertSQL.append(insert).append(" ").append(TableName).append("(").append(ColumnName.toString())
.append(")").append(values).append("(").append(ColumnValue.toString()).append(");");
insertList.add(insertSQL.toString());
System.out.println(insertSQL.toString());
}


public static void main(String[] args) throws Exception {
//String file1 = "/config/export_sqlite_data_clear.cfg";
//executeSelectSQLFile(file1, null);


String file2 = "/config/export_sqlite_data_select.cfg";
executeSelectSQLFile(file2, null);


}
}


代码中应用的cfg文件形式:


select * from t_chapter
select * from t_question_type


使用中目前未发现什么问题,如有BUG,请各位大神改进。


--------------------------------------分割线 --------------------------------------


--------------------------------------分割线 --------------------------------------