Using Cursors

I l @ ve RuBoard

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 update anyway because code that iterates through the rows with cursors is likely to be less efficient and harder to understand.

I l @ ve RuBoard


MySQL and JSP Web Applications. Data-Driven Programming Using Tomcat and MySQL
MySQL and JSP Web Applications: Data-Driven Programming Using Tomcat and MySQL
ISBN: 0672323095
EAN: 2147483647
Year: 2002
Pages: 203
Authors: James Turner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net