File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes preparedStatement - increase column value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "preparedStatement - increase column value" Watch "preparedStatement - increase column value" New topic

preparedStatement - increase column value

timothy smith

Joined: Jun 07, 2007
Posts: 11
Hello all!

i would like to do the following: there is a table in my database with several columns. i want to increase the value in one of them. Which one is not known, it depends on the value of one parameter of the function . i declare using preparedStatement.setString() which column is to be changed. My problem is that i dont know how to write the query so as to achieve this increament.
something like update user_statistiks set ? = ?+1 where USER_ID = ? doesnt work.. the second questionmark is the problem..
does anyone know how i could write my query?

thanks in advance!
Vasilis Karas

Joined: Mar 16, 2004
Posts: 24
You can do it a couple of ways:
The first requires executing two SQL statements.
One to retrieve the row you wish to update, and then one SQL to perform the update. That's the first way.

Second way is to create an "updatable resultset" by doing the following:

Sun ResultSet (Java 2 Platform SE v1.4.2)
timothy smith

Joined: Jun 07, 2007
Posts: 11
hello! i tried the second way but i couldn't get it working! so i did the first one! thanks for the reply!
I agree. Here's the link:
subject: preparedStatement - increase column value
It's not a secret anymore!