Parece que não dá pra anexar códigos às
mensagens.
De qq modo, aqui vão eles.
*********************INSERT********************** // para inserir uma imagem no banco de dados import java.io.*; import java.util.*; import java.sql.*; public class BlobInsert { Connection conn; public BlobInsert() throws SQLException{ DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); conn = DriverManager.getConnection ("jdbc:oracle:thin:@192.168.100.5:1521:quiz","clube", "clube000"); } public void sendToDB(){ String pathname = "/tmp/"; String name = "code2.gif"; InputStream in = null; try{ File pictFile = new File(pathname+name); int pictFileSize = (int) pictFile.length(); in = new FileInputStream(pictFile); PreparedStatement pstmt = conn.prepareStatement("insert into media values ('"+name+"',?)"); pstmt.setBinaryStream(1,in,pictFileSize); pstmt.executeUpdate(); System.out.println("Inseri " + pictFileSize + " bytes!"); } // de try catch (Exception e) { e.printStackTrace(); } }// de sendToDB public static void main(String[] args){ try{ BlobInsert w = new BlobInsert(); w.sendToDB(); } catch(Exception e){ e.printStackTrace(); } }// de main }// de BlobInsert ************************SELECT*********************** // para recuper uma imagem de uma coluna blob do banco de dados import java.io.*; import java.util.*; import java.sql.*; public class BlobSelect { Connection conn; PreparedStatement pstmt; ResultSet rs; public BlobSelect() throws SQLException{ DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); conn = DriverManager.getConnection ("jdbc:oracle:thin:@192.168.100.5:1521:quiz","clube", "clube000"); pstmt = conn.prepareStatement(""); } public void sendToDB(){ String pathname = "/tmp/"; String name = "code2.gif"; FileOutputStream out = null; try{ pstmt = conn.prepareStatement("select data from media where name='" + name + "'"); rs = pstmt.executeQuery(); if (rs.next()){ out = new FileOutputStream("/tmp/retorno.gif"); byte[] b = rs.getBytes(1); out.write(b); System.out.println("Recuperei " + b.length + " bytes!"); }// de if } // de trytry catch (Exception e) { e.printStackTrace(); } }//de sendToDB public static void main(String[] args){ try{ BlobSelect w = new BlobSelect(); w.sendToDB(); } catch(Exception e){ e.printStackTrace(); } }// de main }// de BlobSelect |