There is a database on Oracle and Postgres, you need to use java to unload the necessary tables and distribute them into tables in Postgres, that is, you need to provide some data maration. I understand how to connect, but I don’t understand how to export from oracle first, and then import into postgres.

public class ConnectToOracle { final private static String driverName = "oracle.jdbc.driver.OracleDriver"; private static String url; final private static String server = ""; final private static String port = ""; final private static String sid = ""; final private static String username = ""; final private static String password = ""; private static Connection connection; private static boolean isConnected = false; /*private static Statement stmt; private static ResultSet rs;*/ private static boolean connect() { try { url = "jdbc:oracle:thin:@" + server + ":" + port + ":" + sid; System.out.println(url); Class.forName(driverName); connection = DriverManager.getConnection(url, username, password); System.out.println("connecting: " + url); if(connection.equals(null)) isConnected = false; else isConnected = true; } catch (ClassNotFoundException e) { System.out.println("ClassNotFoundException"); isConnected = false; } catch (SQLException e) { System.out.println("SQLException\n" + e.getMessage()); isConnected = false; } return isConnected; } } 

I will be grateful for any explanations! thank you in advance!

  • We break a task into parts. 1. Connection (this is). 2. Getting a list of tables. 3. Getting the table structure for each table from item 2. 4. Getting the list of indexes for the table. 5. Formation of a request to read data in batches of N rows from the target table. 6. Forming a query to create a target table in the target database (namely, the table, while not pasting the data). 7. Formation of a request to insert data into the target table, in accordance with the set of fields from the source table and their type. 8. Reading data from the source. 9. Inserting a data stack after reading into the target table. - DimXenon
  • Thank you, but I would also like to look at some sample code ... not completely clear - Aleksander Shakotko
  • Here is an example docs.oracle.com/javase/tutorial/jdbc/basics/… . Briefly: with the help of the connection object, we prepare the request with the createStatement method or the like (there are several methods for preparing the request). We send data to the request or execute it right away (depending on whether we need the parameters in the request or not). Next, we get the result object: ResultSet. From this object, you can get data of various types (here dmivic.chat.ru/JDBC/mapping.doc.html about data types and their correspondence in paragraph 8.6.1 and below). - DimXenon
  • Thanks, it helped a lot !!! - Aleksander Shakotko

0