• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please help me out.
thanks in advance.
[ August 24, 2008: Message edited by: Bear Bibeault ]
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"/Harmandeep Singh/", please check your private messages for an important administrative matter.
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chandan Ghosh it helped.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic