Oracle To Hsql

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<Column> 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();
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值