aspose file tools*
The moose likes JDBC and the fly likes how to store object in  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to store object in  "ms access database"  through java?" Watch "how to store object in  "ms access database"  through java?" New topic
Author

how to store object in "ms access database" through java?

Harmandeep Singh
Greenhorn

Joined: Aug 18, 2008
Posts: 5
please help me out.
thanks in advance.
[ August 24, 2008: Message edited by: Bear Bibeault ]
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

Do you understand how JDBC-ODBC bridge for MS access works and have you done any JDBC coding before? I'd start by telling us how far along you are in setting up the Java/Access bridge before focusing on storing objects.

BTW- do you mean files or text when you say objects?


My Blog: Down Home Country Coding with Scott Selikoff
Harmandeep Singh
Greenhorn

Joined: Aug 18, 2008
Posts: 5
First thanks Scott Selikoff for your response.

Yes i know how JDBC-ODBC bridge works in java.

Actually i am making an entity ejb bean(BMP).In this the primary key i am using is a class. But the problem is i don't know how to store this class(i.e Object) in the access database.

I know how to store the other data types like int,double,String etc through java in access database,but i don't know how to store java classes.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Normally the object you want to store consists of ints, Strings, dates, and other simple things that correspond to columns of the tables in the database. If your design is just to put Java objects into a database table, then almost certainly your design is incomplete.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by harmandeep singh saini:
First thanks Scott Selikoff for your response.

Yes i know how JDBC-ODBC bridge works in java.

Actually i am making an entity ejb bean(BMP).In this the primary key i am using is a class. But the problem is i don't know how to store this class(i.e Object) in the access database.

I know how to store the other data types like int,double,String etc through java in access database,but i don't know how to store java classes.


Any reason you chose Access? I know developers don't always get to make choices of technologies themselves, but unless someone told you too (and they can justify why) I'd swap to a proper database. Entity Beans are an "enterprise" technology, Access and the JDBC-ODBC bridge most definately are not.

Also, why are you doing anything with an Entity Bean? Unless it is out of some perverse curiousity, or again unless someone has mandated it, I wouldn't bother. Entity Beans are flawed (see numerous discussions in the EJB and ORM forums).

Not exactly a helpful response I know - so feel free to tell me that you just have to and I'll shut up. I just hate seeing people waste time struggling with what are bad choices of technology in the first place.
[ August 22, 2008: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

I'm going to echo Paul (probably), but Access + EJB? Ewwww.... ODBC-JDBC bridges are hard enough and JDBC code into Access is kind of ugly to begin with but EJB? That's just asking for misery. I'd ether drop the EJB or drop the Access, can't imagine those two working together in a usable product.
Harmandeep Singh
Greenhorn

Joined: Aug 18, 2008
Posts: 5
OK I dropped access database.
Now i am using oracle.Now how can i store java class object(i.e primary key)in oracle.

Suppose the primary key class is as under


Can you give me the coding for storing this class object in oracle through java.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61226
    
  66

"/Harmandeep Singh/", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

That looks to me like just a wrapper for a String. If it was me, I would just store the String in the database column. Especially since it's a primary key column. Oracle just isn't going to apply the class's rules for equality (and neither is any other database), so once you write a record with an instance of that class stuffed into the primary key, you won't have any way of reading that record back by key.

You'll need to fix the class so that it has a method which returns the String variable.
Chandan Ghosh
Greenhorn

Joined: Jun 13, 2005
Posts: 21
specify your primary key class in ejb-jar.xml file like
<prim-key-class>foo.SimpleIdKey</prim-key-class>

and in your ejbCreate() method, extract the property called 'phone'(if caller generates the pk) from primary key object and map it to the desired column in your SQL INSERT statement.

public foo.SimpleIdKey ejbCreate(foo.SimpleIdKey pk,String sure,String flag )
throws javax.ejb.CreateException{

String sql = "INSERT INTO T_HKM_SISTEMPARAMETRELERI VALUES (?,?,?)";
try
{
PreparedStatement stmt = this.getConnection().prepareStatement(sql);
stmt.setString(1,pk.getPhone());
stmt.setString(2,sure);
stmt.setString(3,flag);
ResultSet rs = stmt.executeQuery();
this.releaseConnection();
}
catch(SQLException ex)
{
throw new CreateException();
}

return pk;
}


Thanks & Regards,<br />Chandan Ghosh<br />SCJP1.4
Harmandeep Singh
Greenhorn

Joined: Aug 18, 2008
Posts: 5
Thanks Chandan Ghosh it helped.
 
 
subject: how to store object in "ms access database" through java?