How I can copy my schema in db2 database into the oracle database with full table structure, columns, data and etc using Java.
I write java code but it does not select all tables. I do not know how many tables are in db2 database and even do not know the name of the tables. I just wanna store all the information and make the same schema in oracle.
public class automateExport {
static String value;
public static void main(String[] args) throws SQLException, ClassNotFoundException {
// ResultSet rs = null;
Connection DB2 = getConnection ();
String sql = "SELECT * FROM SYSCAT.COLUMNS WHERE TABSCHEMA NOT LIKE 'SYS%'";
PreparedStatement mainStmt = DB2.prepareStatement(sql);
ResultSet rs = mainStmt.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
String tableName = null;
StringBuilder sb = new StringBuilder( 1024 );
if ( columnCount > 0 ) {
sb.append( "Create table " ).append( rsmd.getTableName( 1 ) ).append( " ( " );
}
for ( int i = 1; i <= columnCount; i ++ ) {
if ( i > 1 ) sb.append( ", " );
String columnName = rsmd.getColumnLabel( i );
String columnType = rsmd.getColumnTypeName( i );
sb.append( columnName ).append( " " ).append( columnType );
int precision = rsmd.getPrecision( i );
if ( precision != 0 ) {
sb.append( "( " ).append( precision ).append( " )" );
}
} // for columns
sb.append( " ) " );
System.out.println( sb.toString() );
}
private static Connection getConnection() throws ClassNotFoundException, SQLException
{
Class. forName ( "COM.ibm.db2os390.sqlj.jdbc.DB2SQLJDriver" );
Connection connection =
DriverManager.getConnection("jdbc:db2://localhost:50000/navid","navid","oracle");
return connection;
}
}