getCreateTableSQL

private TableInfo getCreateTableSQL(DataBase sourceDB, Connection oraConn,
SqlRecord record) throws Exception {
Statement stmt = oraConn.createStatement();
String sql = "select COLUMN_NAME ,DATA_TYPE,DATA_LENGTH,NULLABLE,DATA_PRECISION,DATA_SCALE from cols"
+ " where table_name='"
+ record.getTableName()
+ "' order by COLUMN_ID";
ResultSet cols = stmt.executeQuery(sql);

TableInfo tableInfo = new TableInfo();
tableInfo.setTablename(record.getTableName());
tableInfo.setDbType("oracle");
List<Column> columns = new ArrayList<Column>();
while (cols.next()) {
Column column = new Column();
column.setColumn_name(cols.getString("COLUMN_NAME"));
String type = cols.getString("DATA_TYPE");
column.setColumn_stype(type);
int lenth = cols.getInt("DATA_LENGTH");
column.setColumn_length(lenth);
String isnull = cols.getString("NULLABLE");
int nullable = 1;
if (isnull.equalsIgnoreCase("N"))
nullable=0;
column.setColumn_nullable(nullable);
column.setColumn_precision(cols.getInt("DATA_PRECISION"));
Integer ct = ColumnTypeMapping.oracleMap.get(type);
if (null == ct) {
System.out.println(type);
column.setColumn_type(0);
} else {
column.setColumn_type(ct);
}
column.setColumn_data_scale(cols.getInt("DATA_SCALE"));
columns.add(column);
}
tableInfo.setColumns(columns);
Primary_Key priKey = sourceDB.getPrimaryKey(record);

tableInfo.setPri_key(priKey);

// String keycols = "";
// add constraint PK_DC_STATUS_DEF primary key (STATUS_TYPE, STATUS_ID)
// String creatKey = "alter table " + priKey.getTableName()
// + " add constraiint " + priKey.getKeyName() + " primary key ("
// + keycols + ")";

String createSql = OracleDataBase.getHQLTableDdlSQL(tableInfo);
tableInfo.setHsqldbCreatTableSQL(createSql);
// tableInfo.setHsqldbCreateKey(creatKey);
stmt.close();
cols.close();
return tableInfo;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值