Join David Gassner for an in-depth discussion in this video Deleting rows with prepared statements, part of Java Database Integration with JDBC.
- View Offline
After inserting and updating, the third operation you need to know how to do is deleting.…In this version of the project DeleteSQL, my main class is collecting an adminID an…integer from the user.…I'll run the code so far and show that it starts by displaying the data and then I can…enter a value and then nothing happens.…I'm going to add code to delete a row from the existing data.…I'll go to my AdminManager class in this version of the project.…I have created the delete method.…The delete method only receives an integer argument.…
It doesn't need an entire JavaBean object, because all it needs to know is the primary…key of the row you want to delete.…As with previous exercises I have seeded this file with the SQL command I'll need, DELETE…FROM and in the name of the table, WHERE and then the primary key column and a placeholder,…which for this table will be an integer.…I'll complete the code by setting the placeholder value.…I'll place the cursor before the return statement, and I'll call this statement objects setInt method.…
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