File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes How Result Set can be upadated while we insert the data programmatcally Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How Result Set can be upadated while we insert the data programmatcally" Watch "How Result Set can be upadated while we insert the data programmatcally" New topic
Author

How Result Set can be upadated while we insert the data programmatcally

Hareesh Ram Chanchali
Ranch Hand

Joined: Jan 31, 2005
Posts: 110
How the result set can be updated if we are inserting the data programmatically.

In my application I am inserting the data rowwise but the inserted row is needed for me for insertion of next row. How can we do it

I am using a servlet in which I have written the JDBC related code to update the data


Hareesh Ram Chanchali
SCJP 5.0, IBM Certified Solution Designer
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
By the way why you need previous row to insert the next row. I can think of incrementing the primary key column value, right? it is not a good approach though.

writing the JDBC code in servlet is another worst thing.

you can have 2 VOs in parallel.
[ February 17, 2005: Message edited by: Adeel Ansari ]
Hareesh Ram Chanchali
Ranch Hand

Joined: Jan 31, 2005
Posts: 110
why means my logic is implementing the primary key exception on its own ( not depending upon SQLException

I am getting the values and cross checking those values with the value to be inserted
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

This is not a Servlet question, moving to JDBC.
Please put more though into where you post your questions.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Hareesh Ram Chanchali:
why means my logic is implementing the primary key exception on its own ( not depending upon SQLException

I am getting the values and cross checking those values with the value to be inserted


Better do select with a condition on primary key, if record found then show whatever message you want otherwise insert the record.

Holding only previous record doesn't make sense to me. What you will do with other records there in the DB, say 5000 or more, then you have to probably load all of those in some of your collection.

By the way, why not relying on the SQLException?
Hareesh Ram Chanchali
Ranch Hand

Joined: Jan 31, 2005
Posts: 110
dear ansari,
What I mean that it is not only previous record that I want rather I need all the records in which recently added record has to be updated. ( that is it should be one of them.

why I am not relying on SQL Exception is that it is not able to clearly identify the column at which the problem has occured

( Here in my Application , I am not aware of DDL script which has been used for creation of the table. Rather I am depending upon Reverse Engineering the Data Model to get all the information of Integrity constraints and by using them I am validating the data before insertion.
Hareesh Ram Chanchali
Ranch Hand

Joined: Jan 31, 2005
Posts: 110
dear Ansari,

My idea is to get the ResultSet only once and it should be updatable if I insert the record so that inserted record will also be considered while I make validation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Result Set can be upadated while we insert the data programmatcally