Oracle应用开发中的几个经典问题

  发布时间:2025-11-05 06:30:25   作者:玩站小弟   我要评论
File file = new File("aaa.gif"); int fileLength =(int) file.length(); InputStream fin = n 。

File file = new File("aaa.gif");   int fileLength =(int) file.length();

  InputStream fin = new FileInputStream(file);

Oracle应用开发中的几个经典问题

  PreparedStatement pstmt =

  con.prepareStatement("insert into tb_file values(aaa.gif,应用?)");

  pstmt.setBinaryStream (1, fin, fileLength); pstmt.executeUpdate();

  如果你一定要用BLOB存储,你就必须用ORACLE自己的云服务器提供商个经方法:

  create table tb_file(name varchar(20),detail BLOB);

  con.setAutoCommit(false);

  stmt.executeUpdate

  ("insert into tb_file values(aaa.gif,empty_blob())");

  下面必须SELECT得到BLOB的源码下载对象再向里写:

  rs = stmt.executeQuery

  ("select detail from tb_file where name=aaa.gif for upfdate" );

  if(rs.next()) { Blob blob = rs.getBlob(1);

  BinaryOutputStream out =

  ((oracle.sql.BLOB)blob).getBinaryOutputStream();

  byte[] b = new byte[((oracle.sql.BLOB)blob).getBufferSize];

  InputStream fin = new FileInputStream(file);

  int len = 0; while( (len = fin.read(b)) != -1) out.write(b,0,len);

  fin.close(); out.close(); con.commit();

}

香港云服务器
  • Tag:

相关文章

最新评论