R Bayo R Bayo - 17 days ago 6
Java Question

logging issue while using jdbc

I'm using jdbc for the first time and reading from a file which contains sql queries I wrote earlier. Although the queries are properly executed and my program goes on without any apparent issue, After I've

statement.executeBatch();
, I cannot write anything into my log anymore.

-I'm using the
java.util.logging
to do my logging with a
FileHandler
. To read my ".sql" file, I'm using a
BufferedReader
and a
FileReader
. I know I'm not sharing a lot of code to fully understand the context, but that's all I have from memory. I'm closing all the readers after use.

Any ideas what could be the problem?

MyLogger.log(Level.WARNING, "it does write");
statement.executeBatch();
MyLogger.log(Level.WARNING, "it doesn't write anymore");
statement.close();
MyLogger.log(Level.WARNING, "still doesn't");


Thanks

edit: MyLogger is a class with a statig log method

edit2: @Tim Biegeleisen
statement.executeBatch()
returns an array of int, one for each batch. I tried :

try {
int[] results = statement.executeBatch();
for (int result : results)
{
if (result == Statement.EXECUTE_FAILED)
{
MyLogger.log(Level.SEVERE, "batch failed, but driver seems to still be alive.");
System.out.println("batch failed, but driver seems to still be alive.");
}
}

} catch (SQLException e) {
MyLogger.log(Level.SEVERE, "the batch failed, and the driver died too.");
System.out.println("the batch failed, and the driver died too.");
}


and it printed and logged nothing.

edit3: I guess I was asking too much of my shutdown hook. I'm not familiar with it so I'm not sure what was precisely the problem.

Answer

The explanation which seems most likely to me is that your code is rolling over upon hitting executeBatch(). After this, the subsequent calls to the logger do not appear to be working, because they aren't being hit at all. One simple way to test this would be to surround your call to executeBatch() with a try catch block:

try {
    int result = statement.executeBatch();
    if (result == Statement.EXECUTE_FAILED) {
        MyLogger.log(Level.ERROR, "batch failed, but driver seems to still be alive.");
    }
} catch (SQLException e) {
    MyLogger.log(Level.ERROR, "the batch failed, and the driver died too.");
}