Inserting, Deleting, and Updating

Instead of using executeQuery on a Statement or PreparedStatement, you can use executeUpdate, which returns nothing. This method is used for any non-select SQL function. Here are a few examples showing what you can do with executeUpdate:

 Statement st = conn.createStatement(); st.executeUpdate("delete from employees"); PreparedStatement pst = conn.prepareStatement("INSERT INTO employees (lname_txt, fname_txt, employee_num) "+ "values (?, ?, ?)"); pst.setString(1, "Jones"); pst.setString(2, "Bob"); pst.setInt(3, 22); pst.executeUpdate(); pst.close(); pst = conn.prepareStatement("UPDATE employees set employee_num = ? where lname_txt=? and fname_txt = ?"); pst.setString(1, "Jones"); pst.setString(2, "Bob"); pst.setInt(3, ...

Get MySQL™ and JSP™ Web Applications: Data-Driven Programming Using Tomcat and MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.