Join David Gassner for an in-depth discussion in this video Using a persistent database connection, part of Java Database Integration with JDBC.
- View Offline
If you have been working through the exercises in this video series, you might have noticed…that we're opening a lot of database connections.…I'm working in a version of my project called ConnectionManager that has the code for updating a database table.…And I'll go to the tables package and open AdminManager.java.…The way this application is currently architected every time I call my DBUtil class's getConnection…method, I'm opening a new connection, and then I am closing that connection when that method is finished.…And if you count up all the times that we are using the get connection method, you'll…see that we're opening and closing connections many, many times.…
In JDBC this is into great practice, and that's because connections are expensive.…They take time, memory, and resources, and so to the extent possible you should minimize…the opening and closing of connections by reusing connections.…When you work in a Java Enterprise Edition Server environment such as JBoss, the server…typically will provide connection pooling.…
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