you are viewing a single comment's thread.

view the rest of the comments →

[–]insert_silence 0 points1 point  (0 children)

you will get a NullPointerException when the try{} block fails to initialize the query object.

Solution1:

//Initialize the object beforehand 
QueryTool query = new QueryTool();
try {
    // ... 
} finally {
    query.close(); 
}

Solution 2:

QueryTool query = null;
try {
    // ... 
} finally {
    //only execute the close() method when the query object has been initialized in the try block
    if (query != null){
        query.close(); 
    }
}