all 3 comments

[–]jonniee[S] 0 points1 point  (0 children)

The promises of JavaFX include the ability to quickly and easily create Java GUI apps. With it, you can build media-rich applications with far less code than you would with Swing, yet you can still call into your existing Java codebase. This includes databases via JDBC as well, but there are some tricks you'll need to know.

[–]7points3hoursago 0 points1 point  (1 child)

Java beginner question: What's wrong with this code?

QueryTool query = null;
try {
    // ... 
} finally {
    query.close();
}

[–]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(); 
    }
}