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

Using Cursors

Another way to update or delete data is to use a cursor. While looping through the results of a query, you can modify, delete, or add records, but only if you set up the statement the right way.

By default, when you execute a query, it's run in a kind of “read-only” mode. You can step through the values using the next() method on the record set, but that's it.

If the code hands an extra pair of arguments to createConnection or prepareStatement, you can create a ResultSet that can move back and forth inside the query, as well as update and append to.

Unfortunately, as of the current release of the MySQL JDBC driver, this is a not-ready-for-prime-time feature. Luckily, most of the time you are better off doing an explicit insert or ...

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