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();
        }
  • 相关阅读:
    LeetCode-Letter Combinations of a Phone Number
    LeetCode-Sort Colors
    C++Memset误区
    LeetCode-Valid Palindrome
    LeetCode-Longest Consecutive Sequence
    C++豆知识索引
    C++ 哈希表
    LeetCode-Sum Root to Leaf Numbers
    LeetCode-Word LadderII
    LeetCode-Word Ladder
  • 原文地址:https://www.cnblogs.com/xue88ming/p/7183005.html
Copyright © 2011-2022 走看看