private void saveBinary(InputStream in, Long userId, String remark) {
        Sql sql = new Sql("insert into 表名 (id,CONTENT,USER_ID,REMARK) values(序列.NEXTVAL,?,?,?)");
        sql.addParameter(new Parameter(DataType.BLOB, in));//需要存的二进制文件流
        sql.addParameter(new Parameter(DataType.LONG, userId));//Long类型
        sql.addParameter(new Parameter(DataType.STRING, remark));//String类型
        dao.execute(sql);
    } 

 public InputStream getBinary(String sql) {
        InputStream fis = null;
        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            conn = ContextUtil.getConnection();
            // --
            pstmt = conn.prepareStatement(sql);
            ResultSet rs = pstmt.executeQuery();
            if (rs.next()) {
                fis = rs.getBinaryStream(1);
            }
            rs.close();
            // --
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
        return fis;
    }

 

相关文章:

  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
  • 2022-02-27
  • 2022-12-23
  • 2021-12-28
相关资源
相似解决方案