Solved

Update a record through JDBC

Posted on 2006-06-20
11
212 Views
Last Modified: 2010-08-05
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
Comment
Question by:_Esam
  • 5
  • 4
  • 2
11 Comments
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 16943940
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
 

Author Comment

by:_Esam
ID: 16944070
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
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 16944339
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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
LVL 86

Expert Comment

by:CEHJ
ID: 16944416
Use an updatable ResultSet
0
 

Author Comment

by:_Esam
ID: 16944448
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
 

Author Comment

by:_Esam
ID: 16944472
>Use an updatable ResultSet

How ?
Please show me for clarity!

Thanks.
_Esam
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16944487
You already know - you did it before ;-)
0
 
LVL 10

Accepted Solution

by:
mukundha_expert earned 50 total points
ID: 16944510
try this,

its working in sqlserver,

"update table_name set col_name = colname+1 where col_key = value"
0
 

Author Comment

by:_Esam
ID: 16944518
Didn't work for me ! :)
Let us make it work !

_Esam
0
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 16944542
wat is the datatype of that column??
0
 

Author Comment

by:_Esam
ID: 16944801
Sorry mukundha...
It finally worked ..   can't be sure what the problem was..

Luckily the datatype is a number..

Thanks..
_Esam
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question