Re: Oracle LONG RAW/C#/ADO.NET
From: lanciahf <member_at_dbforums.com>
Date: 15 Jan 2002 10:14:49 -0500
Message-ID: <3c444769$3_at_usenetgateway.com>
Date: 15 Jan 2002 10:14:49 -0500
Message-ID: <3c444769$3_at_usenetgateway.com>
Below is a simpler & faster example!
import java.sql.*; import java.io.*; import java.text.*; import java.util.*; import oracle.jdbc.driver.*;
public class fastPic { jdbcImage iConn = new jdbcImage();
int imageId; int rec;
public fastPic() { 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 ResultSet rs = stmt.executeQuery ("SELECT imageId FROM images"); // process the ResultSet data while (rs.next()) { imageId = rs.getInt("imageId"); rec++; System.out.println(imageId+" "+rec); 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 image table ResultSet rss = stmt2.executeQuery ("SELECT image_data FROM images where imageId = "+imageId); // process the ResultSet data while (rss.next()) {//TRICK IS TO READ IN BYTES AND NOT USE AN INPUTSTREAM!!!! byte mydata[] = rss.getBytes (1); ByteArrayInputStream is = new ByteArrayInputStream(mydata); PreparedStatement pstmt2 = conn2.prepareStatement ("INSERT INTO new_image_table values ("+imageId +",?)"); // use a prepared INSERT for webimages // Get Length of Toots Array for insert. int tLen = mydata.length; pstmt2.setBinaryStream(1, is, tLen); ppstmt2.execute(); pppstmt2.close(); } // 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 static void main (String args[]) { fastPic gp = new fastPic(); }
}
-- an oracle fan, an oracle beginner Posted via dBforums http://dbforums.comReceived on Tue Jan 15 2002 - 16:14:49 CET