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;
}

你可能感兴趣的:(oracle,sql)