Oracle operation picture
Blobtest.java
Created with jbuilder
Package testApp;
Import java.sql. *;
Import java.io. *;
public class Blobtest {public Blobtest () {} public static void main (String args []) throws SQLException, IOException {// write (); read ();} static void read () throws SQLException, IOException {DriverManager.registerDriver ( new oracle.jdbc.driver.OracleDriver ()); // Connect to the database // You can put a database name after the @ sign in the connection URL Connection conn = DriverManager.getConnection ( "jdbc: oracle: thin: @. Ebizser: 1521: ServerDB "," Scott "," Tiger "); // it's faster when you don't commit automatically conn.setautocommit (false); // Create a statement statement stmt = conn.createstatement (); // Do a query to get the row with name 'streamexample' resultSet Rset = stmt.executeQuery ("Select Col2 from Lobtest Where Userid = 1"); // Get The First Row IF (RSET.NEXT ()) {// Get The Data as a stream from oracle to the client input.getbinaryStream (1); // Open a file to store the gif data fileoutputstream OS = New Fil EoutputStream ("eXample.jpe"); // loop, reading from the gif stream and write to the file int C; while ((c = gif_data.read ())! = -1) Os.Write (C); / / Close the file os.close ();} // close all the resources if (rset! = Null) Rset.Close (); if (stmt! = Null) stmt.close (); if (conn! = Null) conn.close ();} static void write () throws SQLException, IOException {DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver ()); // Connect to the database // You can put a database name after the @ Sign in the connection url. Connection conn = //drivermanager.getconnection ("JDBC: Oracle: Thin: @
Ebizser: 1521: ServerDB, "Scott", "Tiger"); DriverManager.getConnection ("JDBC: Oracle: OCI8: @EBDB", "Scott", "Tiger"); // it's Faster When you don't commission Automatic or conn.setautoCommit (false); // Create a statement file file = new file ("c: // Documents and settings // gzb.ecom // my documents // my pictures // 28-3-16933_jinxishan34s.jpe" ); InputStream is = new FileInputStream ( "C: // Documents and Settings // gzb.ECOM // My Documents // My Pictures // 28-3-16933_jinxishan34s.jpe"); PreparedStatement pstmt = conn.prepareStatement ( "insert INTO LOBTEST (UserID, Col2) Values (?,?) "); PSTMT.SetBinaryStream (2, IS, (int) file.Length ()); PSTMT.Setint (1, 2); pstmt.execute (); if (PSTMT! = null) PSTMT.Close (); if (conn! = null) conn.close ();}} blobtest.java
Created with jbuilder