I put this on the back burner for a while, but now it's popped up on my list of things I need to nail down.
Because I'm having this problem connecting to Sybase, but not when running against SQL Server 2012. I went out and upgraded my Sybase jdbc drivers to the latest version and am still having the problem. What is most confusing to me is why this behaves the way it behaves differently during a debug session. Consider the following code pulled from ScriptRunner.java:
private StringBuffer handleLine(StringBuffer command, String line) throws SQLException, UnsupportedEncodingException {
String trimmedLine = line.trim();
if (lineIsComment(trimmedLine)) {
println(trimmedLine);
} else if (commandReadyToExecute(trimmedLine)) {
command.append(line.substring(0, line.lastIndexOf(delimiter)));
command.append(LINE_SEPARATOR);
println(command);
executeStatement(command.toString());
command.setLength(0);
} else if (trimmedLine.length() > 0) {
command.append(line);
command.append(LINE_SEPARATOR);
}
return command;
}
private void executeStatement(String command) throws SQLException, UnsupportedEncodingException {
boolean hasResults = false;
Statement statement = connection.createStatement();
statement.setQueryTimeout(50000);
if (stopOnError) {
hasResults = statement.execute(command);
} else {
try {
hasResults = statement.execute(command);
} catch (SQLException e) {
String message = "Error executing: " + command + ". Cause: " + e;
printlnError(message);
}
}
printResults(statement, hasResults);
try {
statement.close();
} catch (Exception e) {
// Ignore to workaround a bug in some connection pools
}
}
If I step into the executeStatement method (first bolded line), when I reach the statement.execute() call (second bolded line), the delete happens. I can verify this by externally looking at the rows in the table through isql. If I instead step over the first executeStatement, I get no error message, but the row still exists in the database.
I'm convinced this isn't a caching issue because I am verifying the existence of the row completely externally. If it is a transaction issue, then the transaction is getting rolled back silently somewhere because there are no locks in the database.
One other hint I can find in here is triggers. MyTable has a delete trigger which is cascading deletes to other tables. If I remove this trigger, then the delete happens without a problem. This may be a red herring though since the delete happens fine with isql, and of course most strangely fine if I trace right up to statement.execute.
--Mike