Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

update a ResultSet from the DB

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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:


 
author & internet detective
Posts: 41073
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Raul,
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?
 
raul Alejandro Montero Cruz
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic