aspose file tools*
The moose likes JDBC and the fly likes insert java Object into oracle database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "insert java Object into oracle database" Watch "insert java Object into oracle database" New topic
Author

insert java Object into oracle database

Thil kumar
Greenhorn

Joined: Aug 12, 2008
Posts: 3
Hi,
I want to insert java Object into oracle database..
I am using BLOB column and code as follows ..

Data1 data1=new Data1();
data1.a=500;
data1.b=600;
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbcracleci:@mydb", "username", "pwd");
PreparedStatement pst = con.prepareStatement("insert into obj_temp(user_id,data_object) values (?,?)");
pst.setInt(1,10);
pst.setObject(2,data1);

when executing this .. i am getting "Invalid column type" SQLException..
I am doing this for later use of this object from database..
here i want to get A's value 500 and B's value 600 when i retrieving the object from datadase..

Thnks in Advance,
Thilkumar
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Welcome to JavaRanch

Are you trying to serialise the objects before inserting them into the database?

If you want the "a" and "b" values, it might be more appopriate to design your database to take a and b rather than the whole object.
Thil kumar
Greenhorn

Joined: Aug 12, 2008
Posts: 3
Hi thanks,

here SampleData1 class implements Serializable
Even Serialized it gives "Invalid Column Type" Exception ..

I am doing this for later use that object from db,
ie for,..
SampleData1 data1=(SampleData1 )rs.getObjet("blob_colname");
and here data1 object should contain
data1.a=500
data1.b=600

Thanks
Thilkumar
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

Thil,
I answered this same question you posted in the SUN Java JDBC Forum.

Good Luck,
Avi.
Thil kumar
Greenhorn

Joined: Aug 12, 2008
Posts: 3
Hi,
is it this link?
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/advanced.html

But i couldn't found any related solution?

Thanks,
Thilkumar
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Originally posted by Avi Abrami:
Thil,
I answered this same question you posted in the SUN Java JDBC Forum.

Good Luck,
Avi.
Thank you.

Please when you are posting on more than one forum, tell people on both websites.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: insert java Object into oracle database
 
Similar Threads
use of CLOB,help me.
Sybase text column insert with Hibernate
Converting a String to Clob for insert into DB
java.sql.Timestamp to Oracle date
DB2: Using NOT EXISTS with SYSIBM.DUAL in a complex batch query