Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there a way of storing a resultset in a variable (not copying into arrays etc.)

 
kevin allen
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im looking to find a way to store the results of a ResultSet (containing a query) in memory. This query is simply (Select * from tablename) so im looking for something that replicates the functionality of ResultSet but stores the data in memory.

I want to load all my required data from a database into seperate objects each representing a table and then pass these 'tables' through to classes.
Im doing this to keep all the database connections in one class and get it over and done with, the database isnt very big.

in my dreams its something like this

ResultSet rs;
rs = select * from tablename
datasheet = rs.results

this is very important to me im going

thanks for reading!

 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're going to have to copy this into something at some point of time, because once you close the connection the ResultSet is no longer valid.
 
kevin allen
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you know what I could copy it into? without using arrays, hashmaps etc. somelike that naturally stores data in the same way?
 
Armando Flores Ibarra
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i.m.h.o a ResultSet Object is a "virtual cursor" that points to a row. So you canĀ“t really copy the "content" of the ResultSet.
 
kevin allen
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes I think your right.

ok, ill rephrase

is there anything like a VB dataset control in java?

thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TableModel comes into mind, but a List<Object[]> will be just as good. You can then access an entire row and a single cell as follows:
 
kevin allen
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know but my teacher made it clear he doesnt like casting and the columns may be different data types.

thanks for all your help, im guessing it simply isnt there if your not thinking of it

regards and be well,

kevin
 
Armando Flores Ibarra
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you want to consider using a JPA implementation like Hibernate. This way you can easily manipulate lists of "table objects".
 
Campbell Ritchie
Sheriff
Pie
Posts: 49447
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the JDBC forum as being specific to database connectivity.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic