Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Statement stmt = con.createStatement();S
Hi Stephen,
did an exceptions get thrown? Did you check in sqlplus whether something is
really in the table after
your insert?
after your insert:
psmt.executeUpdate();
put a
psmt.close();
in.close();
and when you are reading the stream back,
change
while((len = movData.read(buf)) != 1){
to
while((len = movData.read(buf)) != -1) {
Don't know if that was just a typo on your part.
Hope some/all of this helps!
Cindy
Stephen Wang wrote:
> 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);
> }
> }
Received on Thu Aug 12 1999 - 19:10:17 CDT