com.huawei.dataconvert.db.convert

private void convertTable(Connection hsqlConn, Connection oraConn,
TableInfo table, DataFilter filter)
{

// TODO Auto-generated method stub
String sql = "select * from " + table.getTablename();
List<Column> columns = table.getColumns();
try
{
ResultSet rs = hsqlConn.createStatement().executeQuery(sql);
Statement oraStm = oraConn.createStatement();
oraConn.setAutoCommit(true);
int count = 0;
while (rs.next())
{
try
{
String insertSql = ColumnTypeMapping.getDataInsertSql(
table, rs);
System.out.println(insertSql);
oraStm.execute(insertSql);
count++;
System.out.println(count);
} catch (Exception e)
{
e.printStackTrace();
}
}
} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

private Map getAllViews(Connection hsqlConn, String username)
{

Map<String, String> viewMap = new HashMap<String, String>();

String sqlFromViewToTable = "SELECT TABLE_NAME, VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS where TABLE_SCHEMA='"
+ username.toUpperCase() + "'";

// StringBuffer hsqlSql = new
// StringBuffer("select to_char(dbms_metadata.get_ddl('VIEW',
// 'DIC_RES_CATEGORYALL_VIEW')) as TableInfo from dual;");
Statement stmt = null;
ResultSet rs = null;
try
{
stmt = hsqlConn.createStatement();

rs = hsqlConn.createStatement().executeQuery(sqlFromViewToTable);

while (rs.next())
{
String viewName = (String) rs.getString(1);
String viewDefinition = (String) rs.getString(2);
viewMap.put(viewName, viewDefinition);
System.out.println(viewName);
System.out.println(viewDefinition);
}
} catch (SQLException e)
{
e.printStackTrace();
}

return viewMap;

}

private List<TableInfo> getTables(Connection hsqlConn, String userName)
{
List<TableInfo> tables = new ArrayList<TableInfo>();
String sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='"
+ userName + "'";
System.out.println(sql);
try
{
ResultSet rs = hsqlConn.createStatement().executeQuery(sql);
while (rs.next())
{
TableInfo table = new TableInfo();
table.setDbType("hsql");
String tableName = rs.getString("TABLE_NAME");
table.setTablename(tableName);
List<Column> columns = null;
columns = getColumns(hsqlConn, userName, tableName);
table.setColumns(columns);
tables.add(table);
}
} catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return tables;
}

private List<Column> getColumns(Connection conn, String userName,
String tableName) throws SQLException
{
List<Column> columns = null;
String sql = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='"
+ userName
+ "' AND TABLE_NAME='"
+ tableName
+ "' ORDER BY  ORDINAL_POSITION ASC";
ResultSet rs = conn.createStatement().executeQuery(sql);
while (rs.next())
{
if (null == columns)
columns = new ArrayList<Column>();
String colName = rs.getString("COLUMN_NAME");
String colTypeName = rs.getString("DATA_TYPE");
int colType = ColumnTypeMapping.hsqlDBMap.get(colTypeName);
String nullable = rs.getString("IS_NULLABLE");
Column col = new Column();
col.setColumn_name(colName);
col.setColumn_stype(colTypeName);
col.setColumn_type(colType);
if (nullable.equalsIgnoreCase("NO"))
{
col.setColumn_nullable(1);
}
columns.add(col);
}
return columns;
}

你可能感兴趣的:(sql)