• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

Update a record through JDBC

Hi,
I need to know how to update a record with jdbc with a previous value in the table column!

I want to update a record and set a count column like count+1 for certain condition?
How I do that?


_Esam
0
_Esam
Asked:
_Esam
  • 5
  • 4
  • 2
1 Solution
 
mukundha_expertCommented:
send a query
create a statement or prepared statement with the query,

               "update table_name set col_name = value where col_key = value"

and call executeUpdate() ;
0
 
_EsamAuthor Commented:
You missed my point, I think...

>"update table_name set col_name = value where col_key = value"  - I know this..

I wanted to know .. how could I do it.. if I wanted to increment the value by 1 ???


_Esam
0
 
mukundha_expertCommented:
select that column, increment it and update the new value to the database,


else write a stored procedure in DB and call that from ur java class
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
Use an updatable ResultSet
0
 
_EsamAuthor Commented:
I couldn't update the Timestamp with the Updatable ResultSet ???

Can't believe circling in the same loop :)

No Stored Procedure for me!! Forbidden for me !! :)

Thanks.
_Esam
0
 
_EsamAuthor Commented:
>Use an updatable ResultSet

How ?
Please show me for clarity!

Thanks.
_Esam
0
 
CEHJCommented:
You already know - you did it before ;-)
0
 
mukundha_expertCommented:
try this,

its working in sqlserver,

"update table_name set col_name = colname+1 where col_key = value"
0
 
_EsamAuthor Commented:
Didn't work for me ! :)
Let us make it work !

_Esam
0
 
mukundha_expertCommented:
wat is the datatype of that column??
0
 
_EsamAuthor Commented:
Sorry mukundha...
It finally worked ..   can't be sure what the problem was..

Luckily the datatype is a number..

Thanks..
_Esam
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now