zoukankan      html  css  js  c++  java
  • Oracle blob demo

        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();
        }
  • 相关阅读:
    尚观寻求帮助
    linux软链接与硬连接
    linux常用命令(三)
    zend 动作控制器
    zend 路由
    ZF组件功能简介
    zend_controller
    linux常用命令(一)
    练习1
    练习1感受:
  • 原文地址:https://www.cnblogs.com/xue88ming/p/7183005.html
Copyright © 2011-2022 走看看