Skip to content

Commit

Permalink
DELETE SQL works now.
Browse files Browse the repository at this point in the history
Avoid Oracle fuck-up to not support createArrayOf('VARCHAR', array) with 'DELETE FROM ...... WHERE NOT IN(?)'
  • Loading branch information
hermann77 committed Sep 20, 2018
1 parent 2eb5246 commit 0dbbf07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 36 deletions.
21 changes: 4 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,23 @@ 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) } }
with 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"
}

26 changes: 7 additions & 19 deletions src/main/java/de/schwarz/emailparser/ParserMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ private static void deleteEmailAddressesFromDB(String databaseName, List<String>

private static void deleteEmailAddressesFromDB(String databaseName, List<String> 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");
Expand All @@ -81,27 +76,20 @@ private static void deleteEmailAddressesFromDB(String databaseName, List<String>
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());
}

}


Expand Down

0 comments on commit 0dbbf07

Please sign in to comment.