From 0dbbf073fe63cba09b82e7fe4a6c48b258ab408d Mon Sep 17 00:00:00 2001 From: Hermann Schwarz Date: Thu, 20 Sep 2018 18:34:01 +0200 Subject: [PATCH] DELETE SQL works now. Avoid Oracle fuck-up to not support createArrayOf('VARCHAR', array) with 'DELETE FROM ...... WHERE NOT IN(?)' --- build.gradle | 21 +++------------ .../de/schwarz/emailparser/ParserMain.java | 26 +++++-------------- 2 files changed, 11 insertions(+), 36 deletions(-) diff --git a/build.gradle b/build.gradle index d512576..f1d4183 100644 --- a/build.gradle +++ b/build.gradle @@ -14,24 +14,12 @@ repositories { sourceCompatibility = 1.8 targetCompatibility = 1.8 -jar { - manifest { - attributes ( - 'Implementation-Title': 'Gradle Quickstart', - 'Implementation-Version': version, - 'Main-Class': 'de.schwarz.emailparser.ParserMain' - ) - } - baseName = 'email-parser' - version = version -} - task fatJar(type: Jar) { manifest { - attributes 'Implementation-Title': 'Gradle Jar File Example', - 'Implementation-Version': version, - 'Main-Class': 'de.schwarz.emailparser.ParserMain' + attributes 'Implementation-Title': 'E-Mail parser', + 'Implementation-Version': version, + 'Main-Class': 'de.schwarz.emailparser.ParserMain' } baseName = project.name + '-all' from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } @@ -39,11 +27,10 @@ task fatJar(type: Jar) { } - dependencies { // Use JUnit test framework testImplementation 'junit:junit:4.12' compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.21' - runtime "mysql:mysql-connector-java:5.1.21" + // runtime "mysql:mysql-connector-java:5.1.21" } diff --git a/src/main/java/de/schwarz/emailparser/ParserMain.java b/src/main/java/de/schwarz/emailparser/ParserMain.java index f105e2a..154b1a1 100644 --- a/src/main/java/de/schwarz/emailparser/ParserMain.java +++ b/src/main/java/de/schwarz/emailparser/ParserMain.java @@ -66,11 +66,6 @@ private static void deleteEmailAddressesFromDB(String databaseName, List private static void deleteEmailAddressesFromDB(String databaseName, List emailAddressesToDelete, String port) { - System.out.println("HERE"); - System.out.println("10. Adresse:" + emailAddressesToDelete.get(10)); - System.out.println("100. Adresse:" + emailAddressesToDelete.get(100)); - - Connection connection = DBConnection.getConnection(databaseName, port); if(connection == null) { System.out.println("connection is null"); @@ -81,27 +76,20 @@ private static void deleteEmailAddressesFromDB(String databaseName, List ResultSet resultSet = null; try { //stmt = connection.createStatement(); - stmt = connection.prepareStatement("DELETE FROM lid_subscribers WHERE nl_email IN (?)"); - Object[] emailAddressesToDeleteArray = emailAddressesToDelete.toArray(); - Array array = connection.createArrayOf("VARCHAR", emailAddressesToDeleteArray); - stmt.setArray(1, array); - int updateCount = stmt.executeUpdate(); - - /* - resultSet = stmt.executeQuery("SELECT nl_email FROM lid_subscribers LIMIT 10"); - while (resultSet.next()) { - String nl_email = resultSet.getString(1); - System.out.println("DB e-mail address: " + nl_email); + for(String address : emailAddressesToDelete) { + stmt = connection.prepareStatement("DELETE FROM lid_subscribers WHERE nl_email IN (?)"); + + stmt.setString(1, address); + int updateCount = stmt.executeUpdate(); } - */ + } catch (NullPointerException e) { System.out.println("NullPointer"); } catch (SQLException e) { - System.out.println("SQL query not executed: " + e.getErrorCode()); + System.out.println("SQL query not executed: " + e.toString()); } - }