Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Help on Insert and Query Binary Data
Hi all,
I am developing applications and servlets (using Java Web Server
1.1.3
on a NT machine) to query and update databases containing binary data. I
have tried Sybase SQL anywhere and Oracle8i. In Sybase, the field
containing
the binary data was defined as "long binary" and in Oracle, the field
was
defined as "long raw".
The problem I encountered was that I could not query out the binary
file
inserted. I got no data coming out of the query. Below I have provided
the
code that I used for inserting the binary data and querying the binary
data.
Any suggestions are greatly appreciated!!!
Thanks in advance!!!
Stephen
// Insert binary data into a database
PreparedStatement psmt = con.prepareStatement(
"INSERT INTO VIDEOTABLE (PATIENTID, VIDEO) VALUES (?, ?)");
FileInputStream in = new
FileInputStream("d:/JavaWebServer1.1.3/public_html/logout.jpg");
int inBytes = in.available();
byte inBuf[] = new byte[inBytes];
int bytesRead = in.read(inBuf, 0, inBytes);
psmt.clearParameters(); psmt.setString(1, "31313"); psmt.setBinaryStream(2, in, inBuf.length); psmt.executeUpdate();
// To get the binary data out
Statement stmt = con.createStatement(); sql = new String("SELECT IMAGE FROM IMAGETABLE WHERE patientID='31313'");
ResultSet rs = stmt.executeQuery(sql); if(rs.next()){
BufferedInputStream movData = null; movData = new BufferedInputStream(rs.getBinaryStream("VIDEO")); byte[] buf = new byte[4*1024]; //4K buffer int len; while((len = movData.read(buf)) != 1){ out.write(buf, 0, len); }
![]() |
![]() |