• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

preparedStatement - increase column value

 
timothy smith
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello! i tried the second way but i couldn't get it working! so i did the first one! thanks for the reply!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic