Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Harmandeep Singh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me out.
thanks in advance.
[ August 24, 2008: Message edited by: Bear Bibeault ]
 
Scott Selikoff
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Harmandeep Singh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Scott Selikoff
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"/Harmandeep Singh/", please check your private messages for an important administrative matter.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
}
 
Harmandeep Singh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chandan Ghosh it helped.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic