• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Understanding ResultSet

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi - just getting back into java after a hiatus for a year.

For the life of me, ResultSets don't make sense to me. First of all, I'm quite familiar with dealing with cursors and data-table object in other languages, but the behavior of the RS has me stumped. i have no problem connecting and retrieving data or scrolling through, displaying my data on a simple form, etc. My problem is updating. Specifically:

When I updateString() and then immediately check what i just did with getString(), the old/original value is still there? If I updateRow, the new value then shows up, but how can I get the new/current value before or without updating the back-end database? obviously it is there somewhere, because updateRow send it to the database, but how can i retrieve it independently?

Thanks!
KenM

 
Bartender
Posts: 6115
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a bit unclear as to what you are trying to do. It sounds like you are trying to use a ResultSet as a collection that you can manipulate. In my experience a ResultSet is best treated as read-only and that the ResultSet should be converted to a Collection (e.g. List) of a class that will hold all the columns for a row (i.e. a Data Access Object). All manipulations would then be done on the Collection you created, not the ResultSet.
 
Ken Matson
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:I'm a bit unclear as to what you are trying to do. It sounds like you are trying to use a ResultSet as a collection that you can manipulate. In my experience a ResultSet is best treated as read-only and that the ResultSet should be converted to a Collection (e.g. List) of a class that will hold all the columns for a row (i.e. a Data Access Object). All manipulations would then be done on the Collection you created, not the ResultSet.



I guess I am/was hoping that ResultSet or maybe a RowSet WOULD BE the kind of object I'm looking for ... yes ... a DAO. I suppose I am skewed in my expectations, having done most of my work in Visual Fox Pro many years ago that really made these things simple and straightforward. If you're not familiar with it, or other Data-Centric application development tools like Access, Delphi, Powerbuilder, 4th Dimension, etc. then you may be shaking your head, but from my point of view, being able to EASILY handle local-side data cursors with full functionality - not only in and of themselves, but being able to easily map/bind them to gui objects with just some property settings and little to no code, is kind of application development 101 in my mind. i'm just sort of stunned that a language as mature and widespread as Java (and others BTW) doesn't have this baked into the core language.

Ok SoapBox off - having said that, I guess I'll have to look at finding some sort of library or rolling my own as you pointed out.

thanks,
KenM
 
Carey Brown
Bartender
Posts: 6115
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might try Hibernate, it seems to be very popular with the Java crowd (I personally have no experience with it). I was reading about it a couple of years ago and the thing about Hibernate that jumped out at me was its ability to handle transactions in a robust manner.
 
Ken Matson
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, although I haven't fully explored it, the cached data set is doing much of what I want and expect. My initial impression is that I'll be able to make that work. Thanks for the replies! I'm certainly open to any other ideas.
 
Saloon Keeper
Posts: 2680
335
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to be able to scroll forward/backward and make changes to the ResultSet, you need to declare this when you create your Statement.

I haven't looked at this for quite a while, but there is some explanation in this Java tutorial.
 
Rancher
Posts: 478
6
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should take a look at the docs.  It explains how in works in the description.  If you do updatestring/int it will change the value but it won't be changed in the database until you do updateRow/insertRow.
If you are updating the database yourself I don't understand why you wouldn't have the data you're updating or the old data.
 
Sheriff
Posts: 24633
56
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ken Matson wrote:If you're not familiar with it, or other Data-Centric application development tools like Access, Delphi, Powerbuilder, 4th Dimension, etc. then you may be shaking your head, but from my point of view, being able to EASILY handle local-side data cursors with full functionality - not only in and of themselves, but being able to easily map/bind them to gui objects with just some property settings and little to no code, is kind of application development 101 in my mind.



And yet the fact is that Java developers almost never use ResultSet in that way. That's why you're getting responses with a large helping of incomprehension.

When I started with Java, something like 15 years ago, I played around with those methods you described. I too had worked with Access applications before that so it seemed like a reasonable thing to do. But I soon found that it was much more practical to create a ResultSet, read the data from it into a list of problem-specific objects, close the ResultSet and work with that list. What you're trying to do is data-oriented rather than object-oriented, and Java is an object-oriented language.

There are probably people who can explain why your data-oriented approach has problems working with multi-user databases because of transactions and data integrity, but I'm not able to do that. My Access applications should also have had those problems because I had multiple users accessing the same database but (probably by luck) I never had data integrity problems.
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!