• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

insert java Object into oracle database

 
Thil kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thil,
I answered this same question you posted in the SUN Java JDBC Forum.

Good Luck,
Avi.
 
Thil kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic