Using pictures in the page is indispensable in applications. Many times we all put the files directly on the local file system so that image information can be displayed directly in the page. Now I introduce how to retrieve the image information saved in the database and display it in the page. The BLOB stored in the Oralce database is stored. To display pictures, you must have pictures to be stored in the database. The first step we should establish a table.
The table structure is as follows: Test_blob (ID varob) Step Step Step Step Step Step Step Step Step Test We must pour the data into the database to compile the following code: import java.io. *; Import java.sql. *; Import Oracle .jdbc.oracleresultset; import oracle.sql. *; public class testoracle {string username, password; connection conname, password; limitedment stmt = null; {username = "***"; password = "***"; try { Class.Forname ("Oracle.jdbc.driver.Oracledriver"); conn = drivermanager.getConnection ("JDBC: Oracle: Thin: @ 10.150.6.160: 1521: dbwind72", username, password; stmt = conn.createstatement () ;} catch (Exception ex) {System.out.println (ex);}} public void blobInsert (String infile) throws Exception {boolean defaultCommit = conn.getAutoCommit (); conn.setAutoCommit (false); try {System.out .println ("Try Start"); Stmt.executeUpdate ("111 ', EMPTY_BLOB ()") ")"); system.out.println ("stmt.executeUpdate"); // conn.commit () ResultSet RS = Stmt.executeQuery ("SELECT Blobcol from test_blob where id = '111' for update); system.out.println (" stmt.executeQuery "); while (rs.next ()) {Oracle.sql. Blob blob = (Oracle.sql .BLOB) rs.getBlob ( "BLOBCOL"); System.out.println ( "rs.getBlob"); BufferedOutputStream out = new BufferedOutputStream (blob.getBinaryOutputStream ()); System.out.println ( "out stream create") BufferedInputStream in = new bufferedinputstream (New fileinputStream (New fileinputstream (new file)); system.out.println ("Create new input file"); int C; while ((c = in.read ())! = - 1 ) {out.write (c);} in.close (); out.close ();} CONN (Exception ex) {system.out.println ("blobinsert's exception"; conn. Rollback (); throw ex;} conn.setautocommit (DefaultCommit);
} public static void main (string [] args) {testoracle test = new testoracle (); try {test.blobinsert ("r: //onjava_logo.jpg");} catch (Exception EX) {system.out.println "Main's test.blobinsert () Exception" ex);}}} This will save your RD onjava_logo.jpg to the database. Note: BLOB type data must first insert an empty value and then Update cannot be interpreted directly into it. Ok, the preparation work is basically completed, and now we will start our theme. I have directly used a JSP file to transfer image information from the database.