Julia: DataTransport: PostgreSQL -> Oracle

Beitrag lesen

Hallo Forum,

ich möchte bestimmte Daten (nicht komplette DB) aus PostgreSQL auslesen und in Oracle einfügen.

Ich möchte hierfür Prapaired-Statements benutzen. Leider funktioniert es nicht wie es soll: Wenn ich mir die Query ausgeben lasse und in Oracle manuell ausführe, werden die Datensätze hinzugefügt. Über mein Java-Programm mit Prapaired-Statements werden keine Datensätze transportiert.

Hier ist mein Versuch:



public void exportData(Event event) throws SQLException {
        String selectQueryTitle = "SELECT t.* FROM title t JOIN kind_type kt ON t.kind_id = kt.id WHERE kt.kind IN (" + selectTitle + ");"; // selectTitle ist bekannt an der Stelle

        String insertQueryTitle = "INSERT INTO TITLE(ID, TITLE, IMDB_INDEX, KIND_ID, PRODUCTION_YEAR, IMDB_ID, PHONETIC_CODE, EPISODE_OF_ID, SEASON_NR, EPISODE_NR, SERIES_YEARS, MD5SUM) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
        
        con2.setAutoCommit(false);
        try (PreparedStatement pstmt = con2.prepareStatement(insertQueryTitle)) {
            try (Statement stmt = con1.createStatement()) {
                try (ResultSet rs = stmt.executeQuery(selectQueryTitle)) {
                   int chunk = 0;
                   while (rs.next()) {
                        String myQuery = "INSERT INTO TITLE(ID, TITLE, IMDB_INDEX, KIND_ID,   PRODUCTION_YEAR, IMDB_ID, PHONETIC_CODE, EPISODE_OF_ID, SEASON_NR, EPISODE_NR, SERIES_YEARS, MD5SUM) VALUES (";

                        String wert = Integer.toString(rs.getInt(1));
                        if (wert.equals("0")) {
                            wert = "NULL";
                        }
                        myQuery += wert;
                        pstmt.setString(1, wert);

                        wert = rs.getString(2);
                        if (wert == null) {
                            pstmt.setString(2, wert);
                            myQuery += ", " + wert;
                        } else {
                            pstmt.setString(2, "'" + wert + "'");
                            myQuery += ", '" + wert + "'";
                        }

                        wert = rs.getString(3);
                        if (wert == null) {
                            pstmt.setString(3, wert);
                            myQuery += ", " + wert;
                        } else {
                            pstmt.setString(3, "'" + wert + "'");
                            myQuery += ", '" + wert + "'";
                        }

                        wert = Integer.toString(rs.getInt(4));
                        if (wert.equals("0")) {
                            wert = "NULL";
                        }
                        myQuery += ", " + wert;
                        pstmt.setString(4, wert);

                        wert = Integer.toString(rs.getInt(5));
                        if (wert.equals("0")) {
                            wert = "NULL";
                        }
                        myQuery += ", " + wert;
                        pstmt.setString(5, wert);

                        wert = Integer.toString(rs.getInt(6));
                        if (wert.equals("0")) {
                            wert = "NULL";
                        }
                        myQuery += ", " + wert;
                        pstmt.setString(6, wert);

                         wert = rs.getString(7);
                        if (wert == null) {
                            pstmt.setString(7, wert);
                            myQuery += ", " + wert;
                        } else {
                            pstmt.setString(7, "'" + wert + "'");
                            myQuery += ", '" + wert + "'";
                        }

                        wert = Integer.toString(rs.getInt(8));
                        if (wert.equals("0")) {
                            wert = "NULL";
                        }
                        myQuery += ", " + wert;
                        pstmt.setString(8, wert);

                        wert = Integer.toString(rs.getInt(9));
                        if (wert.equals("0")) {
                            wert = "NULL";
                        }
                        myQuery += ", " + wert;
                        pstmt.setString(9, wert);

                        wert = Integer.toString(rs.getInt(10));
                        if (wert.equals("0")) {
                            wert = "NULL";
                        }
                        myQuery += ", " + wert;
                        pstmt.setString(10, wert);

                         wert = rs.getString(11);
                        if (wert == null) {
                            pstmt.setString(11, wert);
                            myQuery += ", " + wert;
                        } else {
                            pstmt.setString(11, "'" + wert + "'");
                            myQuery += ", '" + wert + "'";
                        }
                        
                        wert = rs.getString(12);
                        if (wert == null) {
                            pstmt.setString(12, wert);
                            myQuery += ", " + wert;
                        } else {
                            pstmt.setString(12, "'" + wert + "'");
                            myQuery += ", '" + wert + "')";
                        }

                        System.out.println(myQuery);
                        pstmt.executeBatch();
                    }
                }
                con2.commit();
            }
        }
    }

In der Konsole kriege ich folgende Queries, die (wie gesagt) in Oracle ausführbar sind, aber als prepaired Statement nicht ausgeführt / nicht eingetragen werden.

INSERT INTO TITLE(ID, TITLE, IMDB_INDEX, KIND_ID, PRODUCTION_YEAR, IMDB_ID, PHONETIC_CODE, EPISODE_OF_ID, SEASON_NR, EPISODE_NR, SERIES_YEARS, MD5SUM) VALUES (2247217, 'Incursion', null, 3, 2017, NULL, 'I5262', NULL, NULL, NULL, null, '0c7e272b36c323afe2ac20c13dff854f');

INSERT INTO TITLE(ID, TITLE, IMDB_INDEX, KIND_ID, PRODUCTION_YEAR, IMDB_ID, PHONETIC_CODE, EPISODE_OF_ID, SEASON_NR, EPISODE_NR, SERIES_YEARS, MD5SUM) VALUES (2776338, 'Un asunto de miedo...', null, 3, 2017, NULL, 'A2535', NULL, NULL, NULL, null, 'ee3aef887cfaaefcb075bb3ce9da8b8f');


Hat jemand vielleicht einen Tipp für mich?

Schönen Dank im Voraus!

Julia