Updating Data with the Statement Class

From InterBase
Jump to: navigation, search

Go Up to Modifying Data Using SQL Statements


The executeUpdate statement with a SQL UPDATE string parameter enables you to modify existing rows based on a condition using the following syntax:

int rowCount= statement.executeUpdate(
"UPDATE table_name SET col1 = val1, col2 = val2,
WHERE condition");

For example, suppose an employee, Sara Jones, gets married wants you to change her last name in the “last_name” column of the EMPLOYEE table:

//Create a connection object
java.sql.Connection connection =
java.sql.DriverManager.getConnection(dbURL,properties);
//Create a statement object
java.sql.Statement statement = connection.createStatement();
//insert the new last name into the table
int rowCount = statement.executeUpdate
("UPDATE emp_table SET last_name = 'Zabrinski'
WHERE emp_no = 13314");