Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Statement stmt = con.createStatement(); S

Statement stmt = con.createStatement(); S

From: Stephen Wang <wangste_at_flux.cpmc.columbia.edu>
Date: Thu, 12 Aug 1999 18:59:16 -0400
Message-ID: <37B351C4.C943105A@flux.cpmc.columbia.edu>


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 - 17:59:16 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US