您的位置:首页 > 数据库 > Oracle

Oracle blob demo

2015-11-11 17:07 645 查看
public void saveBlob(String path) throws SQLException, FileNotFoundException, IOException
    {
        //ITRDR_environment.xlsx
        PreparedStatement pstmt= connection.prepareStatement("update blob_FILE set file =?where id =123456");
InputStream is = new FileInputStream(path+"22.xlsx");
        pstmt.setBinaryStream(1, is,is.available());
        pstmt.executeUpdate();
        connection.commit();
        is.close();
    }

    public void getBlob(String path) throws SQLException, FileNotFoundException, IOException
    {
        String query = "SELECT FILE FROM blob_FILE where id =123456";
        java.sql.Blob blob= null;
        preparedStatement = connection.prepareStatement(query);
        resultSet = preparedStatement.executeQuery();
        while (resultSet.next())
        {
            blob = resultSet.getBlob("FILE");
        }
        InputStream ins=  blob.getBinaryStream();
        
        OutputStream ops = new FileOutputStream(new File(path+"11.xls"));
        
        byte[]b = new byte[1024];
        int len = 0;
        while((len=ins.read(b))!=-1)
        {
            ops.write(b, 0, len);
        }
        ops.close();
        ins.close();
    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: