• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Working with (Reading and updating) ResultSets and Statements

 
Greenhorn
Posts: 24
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am developing an application that is pretty much two main ResultSets of data, one is a list of users while the other is a list of tasks the users have completed.

I have a GUI that consists of a combobox of employees and a table of the tasks that employee performed. I would like to just pull the tasks data once for each employee selection event and if the user edits the table, write some code to correlate that to a point in the resultset and make the change there.

Does this sound normal or odd in the sense of what is typically done for a situation like this? Older programs I have written I would execute an UPDATE or INSERT statement directly into the db because the language I used didn't support updatable resultsets.

I guess I'm not really sure what the difference would be, also I wasn't sure if having that resultset floating around would eat up a lot of resources so in that case it would be better to load the table with the data and close the resultset.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I know that people have written JTable implementations whose table model contains a ResultSet. In these implementations, when the user changes something in the JTable that causes the ResultSet to be updated and hence the database is modified. So it's a perfectly reasonable thing to do, provided it fits with the wider usage of the database. You might want to track those implementations down and see if they work for you.

I wouldn't worry about the ResultSet using "a lot of resources". You know what they say about "premature optimization", don't you?
 
Geoff Berl
Greenhorn
Posts: 24
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is an awesome idea I never even thought of, I think I may try that. But that brings another problem I've had in the past, how would I have my JTable access my application's server connection? I tried a few different things last time I worked with JDBC and none of them worked. I'm still getting used to the relationships between classes and how to get them to share specific objects. I'll definitely search the web for some JTable ResultSet implementations though, thanks.

Paul Clapham wrote:You know what they say about "premature optimization", don't you?


Actually... I don't and now I'm curious, unless it's rhetorical.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Geoff Berl wrote:

Paul Clapham wrote:You know what they say about "premature optimization", don't you?


Actually... I don't and now I'm curious, unless it's rhetorical.



So then google it. But for a start here's a link to what Wikipedia says about when to optimize your code: http://en.wikipedia.org/wiki/Program_optimization#When_to_optimize, which is a pretty good introduction to the subject.
 
Geoff Berl
Greenhorn
Posts: 24
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was able to come up with some examples of TableModels that handle resultsets and I tweaked them to fit my program. I was curious wether it would be better to modify the resultset from the methods in the TableModel or would that be better handled from the driver class?

I started modifying my SetValueAt(...) method so that when a user made a change in the table it would alter the resultset. Again, I'm not sure which is best practice. Not so much which is more efficient now but which is more common or is one or the other completely wrong?

I've read a few books on swing and database manipulation but for the most part all of the programs were making the driver class do everything with the resultset. Since my TableModel is customized to work with a ResultSet putting the data in the table I thought it might be neat to customize it to also make changes to the resultset based on the user editing the table.
 
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic