File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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
Bookmark "preparedStatement - increase column value" Watch "preparedStatement - increase column value" New topic
Author

preparedStatement - increase column value

timothy smith
Greenhorn

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
Greenhorn

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
Greenhorn

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: http://aspose.com/file-tools
 
subject: preparedStatement - increase column value