O'Reilly logo

MySQL™ and JSP™ Web Applications: Data-Driven Programming Using Tomcat and MySQL by James Turner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required