Join David Gassner for an in-depth discussion in this video Closing database resources in Java 7, part of Java Database Integration with JDBC.
- View Offline
- Exercise Files
As I have previously described in this video series, JDBC resources need to be closed when you're done with them.…The Connection, the Statement, and the ResultSet are examples of these resources.…In class of JDBC code, which I show in this project Java7Closeable, you declare your resources…first and initially set them to null, then you actually instantiate them within a try…block, as I have done here.…And then you close them in a finally block first, making sure that they're not null so…that you don't cause yet another error.…
Now all of this code can feel a little bit cumbersome, but in Java 6 and prior it's simply required.…Java 7, however, gives us a new syntax called try-with-resources, which when you apply it…to these JDBC resources, can clean up your code significantly.…The try-with-resources syntax looks like this.…You add code after the try keyword and before the code block, create a set of parentheses,…and then you can instantiate your JDBC resources within those parentheses, and they'll be closed…
Author David Gassner explains how to choose a JDBC driver and connect to one or more databases. He also provides detailed instructions on reading, selecting, and updating data; calling stored procedures; managing data via JavaBean classes or with prepared statements; and working with metadata.
- Importing a MySQL database
- Connecting to databases
- Handling JDBC exceptions
- Looping through result sets
- Limiting the number of fetched rows
- Filtering data with prepared statements
- Calling stored procedures
- Inserting, updating, and deleting rows with prepared statements
- Using a persistent database connection
- Committing and rolling back transactions
Skill Level Intermediate
1. Installing Software
2. Getting Started with JDBC
3. Managing Database Resources
Handling JDBC exceptions7m 7s
4. Reading Data
5. Managing Data
6. Using Metadata
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.