Solved

Update a record through JDBC

Posted on 2006-06-20
11
210 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumDigits  challenge 7 62
topping3 challenge 14 51
create a gui in perl 3 46
JDeveloper 12c for 32 bit 4 36
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

746 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

16 Experts available now in Live!

Get 1:1 Help Now