Join David Gassner for an in-depth discussion in this video Filtering data with prepared statements, part of Java Database Integration with JDBC.
- View Offline
So far in this video series, I have shown you how to work with static SQL statements, statements…that are the same when programmed, and when executed at runtime.…But in many applications, you'll need to use parameterized SQL statements, statements where…there are placeholders that you fill in with variable values at runtime.…In JDBC, you do this with a class called PreparedStatement.…The PreparedStatement class lets you set up an SQL statement as a string with these placeholders…and then fill them in with variable values.…
I'll demonstrate this in the project Prepared Statements.…In this version of my console application, I have a static string representing the SQL statement.…Right now, I'm retrieving all of the data from the Tours table.…And then, when I display the data using this version of the displayData method, I'm first…moving the ResultSet cursor to the end of the ResultSet, then getting the row to find…out how many rows I got back.…And then, if I got back zero, I say there were no tours found.…
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