Re: Oracle LONG RAW/C#/ADO.NET

From: lanciahf <member_at_dbforums.com>
Date: 8 Jan 2002 13:13:41 -0500
Message-ID: <3c3b36d5$1_at_usenetgateway.com>


Hi Matt, This is one way of doing it, probably not the fastest. Change your DB to your own. I'm using Oracle's JDBC Driver. If you fiqure out a way with out writing to a flat file please let me know.

Thanks Ralph

import java.sql.*; import java.io.*; import java.text.*; import java.util.*; import oracle.jdbc.driver.*;

public class getPic { jdbcImage iConn = new jdbcImage(); byte[] byteArray = null; InputStream iss = null; byte toots; int SBI; int tLen; int offId;

        public getPic() { startHere(); }

                       public void startHere() {
                       // load the Oracle driver

        try { Class.forName(iConn.driverName); Connection conn = Driver-
        Manager.getConnection(iConn.connectURL,iConn.uName,iConn.uPass);
        // create an SQL statement instance Statement stmt =
        conn.createStatement (); // retrieve image from row ResultSet rs
        = stmt.executeQuery ("SELECT OFF_ID OFF_ID2 FROM images"); //
        process the ResultSet data while (rs.next()) { offId =
        rs.getInt("OFF_ID2"); SBI = rs.getInt("OFF_ID");
        System.out.println(SBI); partTwo();

                }

                            if (rs != null)
                              rs.close();

                           if (stmt != null)
                             stmt.close();

              if (conn != null) conn.close(); } catch (Exception ex){
              System.out.print(ex);}

}

public void partTwo() { // load the Oracle driver

        try { Class.forName(iConn.driverName); Connection conn2 =
        DriverManager.getConnection(iConn.connectURL,iConn.uName,iC-
        onn.uPass);

                  // create an SQL statement instance
              Statement stmt2 = conn2.createStatement ();

      // retrieve image from row ResultSet rss = stmt2.executeQuery
      ("SELECT image_data FROM images where image_object_id = "+offId
      +"AND image_view_type = 'FACE' and active_flag = 'Y'"); // process
      the ResultSet data while (rss.next()) { // get binary stream data
      from result set InputStream web_image = rss.getBinaryStream(1); //
      open operating system file for storing the image FileOutputStream
      ostr = new FileOutputStream ("c:\\face\\face.gif");

                        // fetch-write loop, fetch image data from rs,
                        write to file int i; while ((i = web_image.read
                        ()) != -1) ostr.write (i);

                            // Close the destination output stream
                            ostr.close (); } //try { //
                            Thread.sleep(2000); //
                            }catch(InterruptedException ie) {}

                //SBI = "11"; createImg();

                   // Close all the resources if (rss != null)
                   rss.close();

                           if (stmt2 != null)
                             stmt2.close();

              if (conn2 != null) conn2.close(); } catch (Exception ex2){
              System.out.print(ex2);}

}

public void createImg() { //Create Log File try { Class.forName(iConn.driverName); Connection conn = DriverManager.getConnection(iConn.connectURL,iConn.uName,iConn.uPass);

                  // Create an SQL statement instance
                Statement stmt = conn.createStatement();

                    // Insert data into the img_data column File file =
                    new File ("c:\\face\\face.gif"); InputStream istr =
                    new FileInputStream ("c:\\face\\face.gif");

                    // prepare the INSERT into webimages using
                    parameters PreparedStatement pstmt =
                    conn.prepareStatement ("INSERT INTO web_image values
                    ("+SBI +",?)");

                    // use a prepared INSERT for webimages

                     pstmt.setBinaryStream (1, istr,
                       (int)file.length());
                    ppstmt.execute();

                    // close connection and statement

                           if (pstmt != null)
ppps                            tmt.close();

                    if (conn != null) conn.close(); } catch (Exception
                    ex){ System.out.print(ex); } }


  public static void main (String args[]) { getPic gp = new getPic(); }

}

--
Posted via dBforums
http://dbforums.com
Received on Tue Jan 08 2002 - 19:13:41 CET

Original text of this message