File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes update a ResultSet from the DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "update a ResultSet from the DB" Watch "update a ResultSet from the DB" New topic

update a ResultSet from the DB

raul Alejandro Montero Cruz

Joined: Jun 05, 2008
Posts: 10

I'm creating a java class to manage all related to Database Management (Especifically MySQL) and i've been having trouble while trying to update a ResultSet.

The problem is that I have a method that executes an insert query. When I call it creates a new record on the DB but it does'nt appear in the ResultSet. I know i can simply refill the ResultSet again using a Statement Object and call its executeQuery method, but i find it a memory waste to do that only for a single new row.

is there a way to only update the record i just created?

here is the code that adds the row:

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33117

I think the answer is no. In the Oracle docs they show how you can insert a row into a result set but not to get a new row from the database.

How long lived is your ResultSet that this is a problem?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
raul Alejandro Montero Cruz

Joined: Jun 05, 2008
Posts: 10
The problem is, I use the resultSet object as global for all the things in the class. I don't know if it is the best way though.

let me explain better, i have a method that show the data in a table, filling up the global ResultSet and then showing its contents in the control. When i update something in the database, i call the method in charge of refreshing, in order to see the changes applied to the control.

the last one, what it does is simply clean up the table and call the method that shows the data. Because the ResultSet keeps the same value it appears like nothing happend to the user, when the changes did apply to the database.

if you have any other idea im opened to it
And thanks

heres the code to show the data:
Sisir Chanda

Joined: Jan 03, 2005
Posts: 11
I am not sure why you are hesitant of executing the query just after the update to populate the global resultset. Why you are too much thoughfull about memory.You should be worried by the memory management.

There is no method by means of which you will update/insert/delete any record and keep track of the data; you need to fire query to get the data.
I agree. Here's the link:
subject: update a ResultSet from the DB
jQuery in Action, 3rd edition