I have to work with two database:
- DB2
- Oracle
I have a schema in DB2 database named NAVID
. I want to create the same schema with all tables in Oracle using Java.
public class automateExport {
static String value;
public static void main(String[] args) throws SQLException, ClassNotFoundException {
ResultSet rs = null;
Connection DB2 = getConnection();
String sqlstm = "SELECT * FROM SYSCAT.COLUMNS WHERE TABSCHEMA NOT LIKE 'SYS%'";
PreparedStatement mainStmt = DB2.prepareStatement(sqlstm);
ResultSet query = mainStmt.executeQuery();
}
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;
}
I dont know how to select all tables with columns and create the same tables in db2.
To make such thing i invite you to make multiple methods; the first method must select a table and get those values and copy them into a vector, and the second method take an argument; the vector and take those values and insert them in the second database 'oracle'. If you would like any other informations contact me in my gmail account zahranemehdi@gmail.com.
For this tasks I would recommend you to use an open source project like talend. I use it for different databases such us Oracle, Mysql, Firebird, SQL-Server and It works fine. It has ha DB2 connector but I have not used it. It's an eclipse-hibernate based project and all the code generated is in Java, here you can find the right tutorials to get started.