Basic JDBC Steps
July 5, 2011 Leave a comment
Accessing a database using JDBC involves a number of steps:
- Get a Connection object connected to a database
- Get a Statement object from an open Connection object
- Get a ResultSet from a Statement‘s query execution
- Process the rows from the ResultSet
While the above is the standard pattern, there are variations: Instead of a Statement, you can get a PreparedStatement (which allows a query to be pre-compiled for extra performance when executed repetitively). An update query may only return a count of the number of rows updated, inserted or deleted instead of a ResultSet. There are calls to get information about the database and about ResultSet objects (e.g. the number, names and types of columns). There are calls to support transactional updates to the database.