File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes How to insert an array into Blob using JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How to insert an array into Blob using JDBC" Watch "How to insert an array into Blob using JDBC" New topic

How to insert an array into Blob using JDBC

Bharat Agarwal

Joined: Jun 16, 2001
Posts: 21
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

Joined: Jul 31, 2000
Posts: 13
Here is code to place a serilized object into a SQL Server IMAGE field, the syntax should be about the same....

Hope it helps.

Todd Bush<BR>AIM: RalphWiggam14
Bharat Agarwal

Joined: Jun 16, 2001
Posts: 21
Thanx, I tried to figure it out and I have used the following code almost similar to ur's........

//if (source==Button7)
if( ==Button7)
System.out.println("Button Pressed");
txtfield.append("Button submit pressed");
//if (Image_Name() != null)
String img_id = Image_Name();
txtfield.append("The following image is seen :" + img_id);
//byte img_points[]=land_points_xy[];
//insertBlob(img_id, 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(2, Image_Name());
ps.setBinaryStream(paramindex++, bais, bindata.length);
txtfield.append("should execute the query");
txtfield.append("finished the query");
}catch (SQLException etc) {txtfield.append (etc.getMessage () + "\n");
} catch (Exception se) {txtfield.append(se.getMessage() + "\n");
}// finally {

//}// 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......
I agree. Here's the link:
subject: How to insert an array into Blob using JDBC
It's not a secret anymore!