wood burning stoves 2.0*
The moose likes JDBC and the fly likes Is there a way of storing a resultset in a variable (not copying into arrays etc.) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Is there a way of storing a resultset in a variable (not copying into arrays etc.)" Watch "Is there a way of storing a resultset in a variable (not copying into arrays etc.)" New topic
Author

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

kevin allen
Greenhorn

Joined: Oct 17, 2009
Posts: 10
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

Joined: Oct 27, 2005
Posts: 19722
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
kevin allen
Greenhorn

Joined: Oct 17, 2009
Posts: 10
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

Joined: Oct 17, 2009
Posts: 17
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.


SCJP 6
kevin allen
Greenhorn

Joined: Oct 17, 2009
Posts: 10
yes I think your right.

ok, ill rephrase

is there anything like a VB dataset control in java?

thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

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

Joined: Oct 17, 2009
Posts: 10
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

Joined: Oct 17, 2009
Posts: 17
Maybe you want to consider using a JPA implementation like Hibernate. This way you can easily manipulate lists of "table objects".
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Moving to the JDBC forum as being specific to database connectivity.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is there a way of storing a resultset in a variable (not copying into arrays etc.)