资源简介
朋友手工制作,derby数据库和其他数据库的转换工具,简易实用。高手可直接用命令提示符便可使用该工具
代码片段和文件信息
package com.ibm.crl.dis.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetmetaData;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.linkedList;
import java.util.List;
import java.util.Map;
//流程:放在eclipse下执行,生成derby.sql的文件,导入derby的驱动,以下省略若干字
public class GenerateInsertSql {
public static void generateInsertSql(Map map) throws Exception {
// db2
// String sql =
// “select name from sysibm.systables where creator=‘“+(String)
// map.get(“SRCSCHEMA“)+“‘“;
// derby
String sql = “select a.tablename from sys.systables a sys.sysschemas b where b.schemaname=‘APP‘ AND a.schemaid=b.schemaid “;
List tables = querySql(sql);
File f = new File((String) map.get(“FILEPATH“));
OutputStream os = new FileOutputStream(f);
for (String table : tables) {
byte[] bs = insertSql((String) map.get(“SRCSCHEMA“) table);
os.write(bs);
}
os.close();
}
public static List querySql(String sql) throws Exception {
List list = new ArrayList();
Connection conn = getConnection();
Statement stmt = null;
ResultSet rst = null;
if (conn == null)
return null;
stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY
ResultSet.CONCUR_UPDATABLE);
rst = stmt.executeQuery(sql);
int n = rst.getmetaData().getColumnCount();
while (rst.next()) {
for (int i = 1; i <= n; i++) {
System.out.println(rst.getmetaData().getColumnName(i) + “ “
+ rst.getString(i));
list.add(rst.getString(i));
}
}
conn.close();
return list;
}
public static byte[] insertSql(String schemaName String tableName)
throws Exception {
StringBuffer tablesql = new StringBuffer();
// if (tableName.equals(“MAIN_ITEM_SYS“)
// || tableName.equals(“BILL_LSH_SYS“)
// || tableName.equals(“base_DATA_SYS“)
// || tableName.equals(“CLASSES“)
// || tableName.equals(“base_MENU_FEATURE“)
// || tableName.equals(“MENU“)) {
if (tableName.equals(“main_sale_data“.toUpperCase())
|| tableName.equals(“vice_sale_data“.toUpperCase())
|| tableName.equals(“tenant“.toUpperCase())) {
// if(!tableName.startsWith(“V_“)){
String sql = “select * from “ + schemaName + “.“ + tableName;
Connection conn = getConnection();
Statement stmt = null;
ResultSet rst = null;
List resultList = new linkedList();
try {
stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY
ResultSet.CONCUR_UPDATABLE);
rst = stmt.executeQuery(sql);
} catch (Exception e) {
System.out.print(“insertSql:stmt.executeQuery error:“ + sql);
e.printStackTrace();
}
ResultSetmetaData rsmd = rst.getmetaData();
int length = rsmd.getColumnCount();
StringBuffer sb = new StringBuffer();
s
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2446767 2011-02-11 15:00 derby转sql工具\derby.jar
文件 514328 2011-02-11 15:20 derby转sql工具\derbyclient.jar
文件 5852 2011-02-11 15:00 derby转sql工具\GenerateInsertSql.java
文件 248 2011-03-18 10:31 derby转sql工具\使用方法.txt
目录 0 2011-03-18 10:26 derby转sql工具
----------- --------- ---------- ----- ----
2967195 5
评论
共有 条评论