public void convertAllTable(DataBase sourceDB, Connection oraConn,
Connection hsqlConn, SqlRecord record) throws Exception {
long time = System.currentTimeMillis();
// 建表并导入数据
System.out.println(“创建表” + record.getTableName());
if (null == oraConn) {
throw new Exception(“ORA–00942 table : ” + record.getTableName()
+ ” not exist.”);
}
// String theSql = getCreateTableStmt(oraConn, record);
TableInfo tableInfo = getCreateTableSQL(sourceDB, oraConn, record);
System.out.println(“get tableInfo”);
insertTableInfo(tableInfo,hsqlConn);
System.out.println(“save tableInfo”);
String theSql = tableInfo.getHsqldbCreatTableSQL();
System.out.println(“get table dll”);
// System.out.println(user+” :: “+theSql);
Statement hsqlStmt = hsqlConn.createStatement();
// System.out.println(theSql);
hsqlStmt.execute(theSql);
System.out.println(“table created”);
long time2 = System.currentTimeMillis();
System.out.println(“建表时间:”+(time2-time));
// hsqlStmt.close();
// // 添加主键
// String keySql = tableInfo.getHsqldbCreateKey();
// System.out.println(keySql);
// hsqlStmt.execute(keySql);
// hsqlStmt.close();
// 导入数据
convertData(oraConn, hsqlConn, record);
long time3 = System.currentTimeMillis();
System.out.println(“导入数据时间:”+(time3-time2));
// break;
// 创建索引
convertIndex(oraConn, hsqlConn, record);
System.out.println(“创建索引时间:”+(System.currentTimeMillis()-time3));
Constant.table_count++;
System.out.println(“convert tables count:”+Constant.table_count);
}
private void insertTableInfo(TableInfo tableInfo, Connection conn) {
try {
Statement stm = conn.createStatement();
String tableName = tableInfo.getTablename();
List cols = tableInfo.getColumns();
String front_sql = “INSERT INTO CCARE.UBHAVE_TABLEINFO” +
“( TABLE_NAME, COLUMN_NAME, COLUMN_TYPE, COLUMN_LENGTH,” +
” COLUMN_NULLABLE, COLUMN_SCALE, COLUMN_PRECISION )” +
“VALUES ( ‘”+tableName+”‘, ‘”;
// colname’, ‘coltype’, collength,collnullable , colscale, colpreci)
for(Column col:cols){
String name =col.getColumn_name();
String type =col.getColumn_stype();
int length = col.getColumn_length();
int nullable = col.getColumn_nullable();
int scale = col.getColumn_data_scale();
int precis = col.getColumn_precision();
String sql = front_sql+name+”‘, ‘”+type+”‘, “+length+”, “+nullable+”, “+scale+”, “+precis+”)”;
// System.out.println(sql);
stm.addBatch(sql);
}
stm.executeBatch();
stm.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/hz/131373.html