-1

I have to work with two database:

  1. DB2
  2. 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.

Sergiy Medvynskyy
  • 11,160
  • 1
  • 32
  • 48
  • Please look into this post: http://stackoverflow.com/questions/11878034/how-to-copy-a-schema-in-mysql-using-java It seems exactly what you need. – drgPP Dec 09 '14 at 11:23
  • I need a Java class that connects to DB2 selects all of the tables in a database then connects to Oracle creates all the DB2 database's tables in an Oracle database and finally inserts all their data. – Omid Rastin Dec 09 '14 at 11:54

2 Answers2

0

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.

marsahllDTitch
  • 309
  • 1
  • 8
0

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.

PbxMan
  • 7,525
  • 1
  • 36
  • 40
  • I want to export all my tables and data from db2 to Oracle by using java. for example every time i run my javaCode all tables and data insert to oracle from db2. and this could happen many times in a day. I need java class that 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'. could you please help me for writing this methods. – Omid Rastin Dec 09 '14 at 11:46
  • As I said, I think the best way I know to accomplish this is with Talend. I have done many database migrations with this tools. It produces java jobs that can be tuned up if needed and run when needed. You many need to invest some time learning this tool but it's worth it. Good luck – PbxMan Dec 09 '14 at 11:52
  • Thanx @PbxMan, you mean this software give me java code? – Omid Rastin Dec 09 '14 at 11:54
  • I don't know any specific examples to do what you want in DB2. If you don't find any you gonna have to code it by yourself. I have the feeling that you think it's easier and simpler than it is. You are translating DB2 to SQL Oracle. If you want to do this manually you need to create the tables, and then migrate the data to SQL Oracle. Talend helps you to do the task but it is not an DB2 specific solution, filetypes etc. so you are gonna have to invest time learning it. Unless you find some open source tool or example writen by somebody else it's not going to be as easy as copy,paste and modify – PbxMan Dec 09 '14 at 12:08
  • Yes talend generates code that can be tunned up if needed. – PbxMan Dec 09 '14 at 12:10
  • Could you please give me the link for download talend. – Omid Rastin Dec 09 '14 at 12:12