Join David Gassner for an in-depth discussion in this video Inserting rows with prepared statements, part of Java Database Integration with JDBC.
- View Offline
Once you have created a JavaBean class to represent the structure of a table, you can start adding…code to your application to insert update and delete rows.…I'll start with inserting data.…In this version of the project InsertSQL, my AdminManager class has a new method called Insert.…It accepts an instance of my JavaBean class as an argument, and it already has an SQL command.…An SQL command to insert data looks like this.…It starts with the INSERT command, then into, and the name of the table.…In this admin and then a common delimited list of the column names you are inserting into inside parentheses.…
You follow that with the keyword values and then the values you are inserting also comma…delimited and also in parentheses.…For JDBC, I'm representing those values with the question mark placeholder, and this…method already has the code to create the connection object and a prepared statement.…I'm going to add the code to populate the placeholders with values.…I will move the cursor into the code block after the opening brace and make a little…
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