Join David Gassner for an in-depth discussion in this video Connecting to multiple databases, part of Java Database Integration with JDBC.
- View Offline
To make it easier to switch between databases. I'm going to re-factor the code that I have…written so far, so I can easily switch from MySQL to HSQL by simply passing in a single argument to a method.…My goal is to show that once you have a connection, the code you use to make a request to the…database and process the results is almost exactly the same from one database platform to another.…I'm working in a project called MultiConnect where I have versions of the Main class that…I have already coded in other projects.…
I have one class that connects to MySQL, and I'll test that and make sure that it's working,…and I have one that's connecting to HSQL, and I'll test that as well.…Now, I have created a separate Utility class called DBUtil which only currently has some commented out code.…I'm going to uncomment that code, and you'll see that there are four private strings,…a username and a password, which will be usable on both databases because I have set it up so…that the same user name, and the same password are available on both, and then two versions…
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