String filePath = "e:\\cc.jpg";
            File inFile = new File(filePath);              
            FileInputStream fis;
            fis = new FileInputStream(inFile);           
            byte [] bytes=new byte[fis.available()];   
我现在将图片读到byte [] bytes数组中存到oracle的blob字段中。怎么将byte []数组转化成blob类型啊?从数据库取出blob字段类型图片怎么显示在页面或生成图片啊?

解决方案 »

  1.   

    有点类似:http://blog.csdn.net/trwhoya/archive/2008/11/12/3280142.aspx
      

  2.   

    写入BLOBhttp://www.java2s.com/Code/Java/Database-SQL-JDBC/StoreBLOBsdataintodatabase.htm读取BLOBhttp://www.java2s.com/Code/Java/Database-SQL-JDBC/ReadBLOBsdatafromdatabase.htm这两个是简单的实现
    前两天用了一下IBatis+Spring对BLOB操作,也还算方便~~
      

  3.   

    try {
    conn.setAutoCommit(false);
    stmt.executeUpdate("insert into document(cavern_no,audio_id,TITLE ,ARCHITECTURE_ATTR_VAL ,PAINTED_SCULPTURE_ATTR_VAL,FRESCO_ATTR_VAL,FOKAN_ATTR_VAL,BLOBFILE )values("+"'285',2,'"+name+"','1111','111101','10101','10001',empty_blob())");
    rs = stmt.executeQuery(
    "select BlobFile from document where cavern_no='285' and document_id=1");if (rs.next()) {
    Blob blob = rs.getBlob("BlobFile");
    out = ( (oracle.sql.BLOB) blob).getBinaryOutputStream();
    bufferSize = ( (oracle.sql.BLOB) blob).getBufferSize();
    in = new BufferedInputStream(new FileInputStream(pathname), bufferSize);byte[] b = new byte[bufferSize];
    int count = in.read(b, 0, bufferSize);
    while (count != -1) {
    out.write(b, 0, count);
    amount += count;
    System.out.println("处理了" + amount + "字节.");
    count = in.read(b, 0, bufferSize);System.out.println("处理了" + amount + "字节,成功.");}out.close();
    out = null;
    in.close();
    in = null;
    conn.commit();}
      

  4.   

    只要字段类型是BLOB,如果是用JDBC操作,都可以用Statement.setBytes(String,byte[]);和Statement.getBytes();如果是用JPA的话,只要添加@Lob就可以了
      

  5.   

    你是问输出时如何以图片方式输出吗,只要设定 out输出的 contentType 为 image 就可以。