wood burning stoves 2.0*
The moose likes JDBC 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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
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(evt.target ==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: http://aspose.com/file-tools
subject: How to insert an array into Blob using JDBC
Similar Threads
Inserting image into the oracle database
Connection reset by peer
Reading a blob object from a database
Insert an image file into oracle and open image file from database?(using sql)
Image insertion into database through JDBC