Solved

Update a record through JDBC

Posted on 2006-06-20
11
211 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what is the difference between "sudo su" and "su - root" 6 106
simple java question 3 44
Spring Framework HTTPSession management 1 24
even odd program using while loop 3 31
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now