R Bayo R Bayo - 1 year ago 71
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

, I cannot write anything into my log anymore.

-I'm using the
to do my logging with a
. To read my ".sql" file, I'm using a
and a
. 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");
MyLogger.log(Level.WARNING, "it doesn't write anymore");
MyLogger.log(Level.WARNING, "still doesn't");


edit: MyLogger is a class with a statig log method

edit2: @Tim Biegeleisen
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 Source

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.");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download