Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to insert an array into Blob using JDBC

 
Bharat Agarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone help me out ? It is an urgent. I want to insert an array of integer into the oracle database using Java applets and JDBC. The array to be inserted is in Column with datatype BLOB. I tried to convert the array into bit array but yet it is giving problems. Help me please, TIA.
 
T Bush
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is code to place a serilized object into a SQL Server IMAGE field, the syntax should be about the same....

Hope it helps.
 
Bharat Agarwal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx, I tried to figure it out and I have used the following code almost similar to ur's........

//if (source==Button7)
if(evt.target ==Button7)
{
System.out.println("Button Pressed");
txtfield.append("Button submit pressed");
//if (Image_Name() != null)
String img_id = Image_Name();
System.out.println(img_id);
txtfield.append("The following image is seen :" + img_id);
//byte img_points[]=land_points_xy[];
//insertBlob(img_id, land_points_xy);
insertBlob(land_points_xy);
txtfield.append("BLOB inserted");
}//end of submit button ..................

public void insertBlob(byte[] bindata) {
try {

txtfield.append("Loading JDBC dirver " + "oracle.jdbc.driver.OracleDriver()" + "\n");
DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection(url, usr, password);
txtfield.append("Connected " + "\n");
try {
ByteArrayInputStream bais = new ByteArrayInputStream(land_points_xy);

String query = ("INSERT INTO TEST VALUES(?, ?, ?, ?)");
PreparedStatement ps = conn.prepareStatement(query);
int paramindex=1;
ps.setString(paramindex++,"HI");
ps.setString(paramindex++,"hello");
//ps.setString(2, Image_Name());
ps.setBinaryStream(paramindex++, bais, bindata.length);
ps.setString(paramindex++,"hi");
txtfield.append("should execute the query");
ps.executeUpdate();
ps.close();
txtfield.append("finished the query");
conn.commit();
}catch (SQLException etc) {txtfield.append (etc.getMessage () + "\n");
} catch (Exception se) {txtfield.append(se.getMessage() + "\n");
conn.close();
}// finally {
conn.close();

//}// Ist try ends
}catch (Exception e) {txtfield.append(e.getMessage() + "\n");} //tII nd try catche nds......................

}// method ends
It gives me Connection reset by peer error in IE browser and IOException:Broken pipe in appletviewer.......Can any one help me please......It is urgent......
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic