歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

jsp上傳圖片Linux報no such file or directory問題解決方法

Class.forName("Oracle.jdbc.driver.OracleDriver");
        Connection con = DriverManager.getConnection(
        "jdbc:oracle:thin:@localhost:1521:orcl", "111", "111");
        //處理事務
        con.setAutoCommit(false);
        Statement st = con.createStatement();
        //插入一個空對象
        st.executeUpdate("update cc_ac03 set picture=empty_blob() where aac002='"+idcard+"'");

        //用for update方式鎖定數據行

        ResultSet rs = st.executeQuery(
        "select picture from cc_ac03 where aac002='"+idcard+"'");
        if (rs.next()) {
        //得到java.sql.Blob對象,然後Cast為oracle.sql.BLOB
        oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
        //到數據庫的輸出流
        OutputStream outStream = blob.getBinaryOutputStream();
       
      //  ByteArrayInputStream bis=upload.getFiles().getFile(0).getContentStream();

        //這裡用一個文件模擬輸入流
       // File file = new File(picture);
      //  InputStream fin = new FileInputStream(file);
       
      //  SmartUpload su = new SmartUpload();
       
        //將輸入流寫到輸出流
        byte[] b = new byte[blob.getBufferSize()];
        int len = 0;
        while ( (len = stream.read(b)) != -1) {
        outStream.write(b, 0, len);
        //blob.putBytes(1,b);
       }
        //依次關閉(注意順序)
      //  fin.close();
        outStream.flush();
        outStream.close();
        con.commit();
        con.close();
        }

解決的心得就是一定要把流文件存入數據庫,而不是存本機的東東,不然就會去讀本機的東西了。其實解決非常簡單,過程卻是痛苦的

ByteArrayInputStream stream = upload.getFiles().getFile(0).getContentStream();這兒就已經得到流文件的值啦

Copyright © Linux教程網 All Rights Reserved