aspose file tools*
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 Java 8 in Action this week in the Java 8 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
Author

How to insert an array into Blob using JDBC

Bharat Agarwal
Greenhorn

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
Greenhorn

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
Greenhorn

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();
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......
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to insert an array into Blob using JDBC
 
Similar Threads
Insert an image file into oracle and open image file from database?(using sql)
Reading a blob object from a database
Image insertion into database through JDBC
Connection reset by peer
Inserting image into the oracle database