Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do we store and retrieve an object in Database table?

Status
Not open for further replies.

TomBarns

Programmer
Feb 14, 2001
10
US
Hi All
I need to store a reference to an object in database table?
how do we do that? how do we retrieve that reference too?
please little sample code.
thanks.
 
hello

with Java there is no possibility for pointer usage like in C and C++

try this :

use a 'java.util.HashMap' object and associate an 'id' to an object. then store the id in the database.
you can then easily retrieve the object with its 'id'.

// storing an object

int id = 0;
MyClass myObject = new MyClass(...);

id++;
HashMap hm = new HashMap();

hm.put(new Integer(id), myObject);

// here you can store 'id' in the database

// retrieve the object

id = // get from the database

myObject = (MyClass)hm.get(new Integer(id));

that's all

manu0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top