Join David Gassner for an in-depth discussion in this video Executing a static SQL statement, part of Java Database Integration with JDBC.
- View Offline
Once you have connected to a database, the next step is typically to send a request, and the…most common sort of request is a simple SQL statement that retrieves data from the database.…I'll show how to do this using the Statement interface and another interface named ResultSet,…which encapsulates the data that's returned from the database.…I'm working in a project called StaticSQL. This project's main class already has the…code to connect to the database.…It has the three strings, the User name, Password, and Connection string.…
And I'm working with an HSQLDB database.…In addition to the connection, I also need an instance of Statement and an instance of ResultSet.…When you call methods of these interfaces, just as with the methods of the…Connection class, they might throw an SQL exception.…So typically, you'll declare the objects outside of the try block and then execute their methods…within the try block, and that will make them have the lifetime invisibility that you need.…I'll move my cursor after the Connection declaration, and I'll declare a Statement.…
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