Join David Gassner for an in-depth discussion in this video Updating rows with prepared statements, part of Java Database Integration with JDBC.
- View Offline
So far in this chapter I have described how to create the JavaBean class to represent…a single row of data and how the insert new data into a database table.…Now I'll show how to update existing data.…Working in a version of my project called UpdateSQL, I have added a new method to the…AdminManager class. The method is named Update.…It receives a single argument, data typed as the Admin JavaBean, and it has an SQL statement.…The SQL statement follows the standard for all updates in SQL.…
It starts with the keyword UPDATE and then the table name admin and then SET,…then there's a series of column name value pairs.…I'll be updating two of the values, the userName and password, and then there is a WHERE clause…that filters the statement so that these changes are only applied to a single row.…This method already has code to create the connection and the prepared statement.…I'll add code now to pass the values from the Bean argument into the prepared statement.…I'll place the cursor after the opening brace and before the return statement and make a…
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