首页 > 代码库 > oracle 数据库存放读取二进制文件(将上传的文件流存在数据库)

oracle 数据库存放读取二进制文件(将上传的文件流存在数据库)

private void saveBinary(InputStream in, Long userId, String fieldName) {        Sql sql = new Sql("insert into EEAS_USER_ATTH(id,CONTENT,USER_ID,ATTH_NAME) values(SEQ_EEAS_USER_ATTH.NEXTVAL,?,?,?)");        sql.addParameter(new Parameter(DataType.BLOB, in));        sql.addParameter(new Parameter(DataType.LONG, userId));        sql.addParameter(new Parameter(DataType.STRING, fieldName));        service.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;    }

 

oracle 数据库存放读取二进制文件(将上传的文件流存在数据库)