| 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: 19216
|
|
|
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
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: 19216
|
|
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: 32694
|
|
|
Moving to the JDBC forum as being specific to database connectivity.
|
 |
 |
|
|
subject: Is there a way of storing a resultset in a variable (not copying into arrays etc.)
|
|
|