问题:我是学java的,数据库用的是oracle.平时都是直接在oracle中存取的图片的地址。请问怎么样在oracle中存取图片和读取图片?
特此请教各位大虾,希望多给出几种解决方案(不要直接在页面上用 JSP 写的那一种)

解决方案 »

  1.   

    一般都是将 图片的路径存到 db中,存取图片可以用 File 类型进行上传,保存路径。
    然后读取的时候直接<img src='路径'/>就可以了
      

  2.   

    第1步,先把文件上传到服务器
    第2步,把上传的文件读进流里,写到数据库的blob字段里参考以下代码public int uploadXXXXX(int id, InputStream inputStream) throws ArchivesException {
            PreparedStatement pstmt = null;
            Connection conn = null;
            String strSQL = null;
            ResultSet rs = null;        try {
                conn = this.getConnection();
                strSQL = "SELECT CONTENT FROM TableName WHERE ID= ? FOR UPDATE";            pstmt = conn.prepareStatement(strSQL);
                pstmt.setInt(1, id);            rs = pstmt.executeQuery();
                if (rs.next()) {                OracleThinBlob blobContent = (OracleThinBlob) rs.getBlob("CONTENT");
                    OutputStream outStream = blobContent.getBinaryOutputStream();                byte[] b = new byte[blobContent.getBufferSize()];                int len = 0;                while ((len = inputStream.read(b)) != -1) {
                        outStream.write(b, 0, len);
                    }                outStream.flush();
                    outStream.close();
                }
            } catch (SQLException ex) {
                logger.error("更新文档内容时出错", ex);
                throw new ArchivesException("更新文档内容时出错", ex);
            } catch (Exception ex) {
                logger.error("更新文档内容时出错", ex);
                throw new ArchivesException("更新文档内容时出错", ex);
            } finally {
                this.closeConnection(rs, pstmt, conn);
            }
            return 1;
        }
    "CONTENT"就是数库所存放图片的字段名,必须是blob类型
      

  3.   

    类型用blob 在读取的时候使用JDBC建立一条通道,然后从数据库中读取数据。存也是一个道理