CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  Web 开发

急死人了,文件存放到ORACLE中的BLOB下,怎么不能超过4K???要怎样才能超过4K?

楼主yeyoujian(yeyoujian)2003-03-03 12:52:19 在 Java / Web 开发 提问

1.   rs   =   stmt.executeQuery("SELECT   FILESTREAM   FROM   BLOBTEST   WHERE   ID=1");  
        执行到该语句时,JAVA报“java.sql.SQLException:   ORA-01002:   读取违反顺序”  
        错误,怎么回事?  
   
  2.   用“INSERT   INTO   BLOBTBL(ID,BLOBFIELD)VALUES(1,?)”  
        stmt.setBinaryStream(1,   fis,   (int)file.length());    
        超过4K的文件保存不进去,WHY??  
   
        急急急!!!!! 问题点数:0、回复次数:1Top

1 楼chensoushi(不记得了)回复于 2003-03-03 13:48:59 得分 0

请参考一下以下的代码,看对你是否有用  
  import   oracle.sql.BLOB;  
  import   oracle.jdbc.driver.OracleResultSet;  
  import   oracle.jdbc.driver.*;  
  import   java.io.*;  
  import   java.sql.*;  
  import   java.sql.Blob;  
   
  public   class   Upload{  
       
      public   static   void   main   (String   args   []){  
      Connection   myConn   =   null;  
  Statement   stmt   =   null;  
  ResultSet   rset   =   null;  
  FileInputStream   fileinput   =   null;  
  OutputStream   outstream   =   null;  
  PreparedStatement   ps   =   null;  
   
  try{  
        //   Load   the   Oracle   JDBC   driver  
              DriverManager.registerDriver(new   oracle.jdbc.driver.OracleDriver());  
        //   Connect   to   the   database  
        //   You   must   put   a   database   name   after   the   @   sign   in   the   connection   URL.  
        //   You   can   use   either   the   fully   specified   SQL*net   syntax   or   a   short   cut  
        //   syntax   as   <host>:<port>:<sid>.     The   example   uses   the   short   cut   syntax.  
        //myConn   =   DriverManager.getConnection   ("jdbc:oracle:thin:@172.16.4.58:1521:weboa",  
  //       "oa",   "password");  
        myConn   =   DriverManager.getConnection   ("jdbc:oracle:thin:@172.16.4.58:1521:weboa",  
        "oa",   "password");  
        //   Create   a   Statement  
  myConn.setAutoCommit(false);  
   
  stmt   =   myConn.createStatement();  
  String   sql   =   "insert   into   AttachedDocumentInfo(DocumentID,DocumentContent)   "+  
                              "values   ('111',empty_blob())";  
  stmt.execute   (sql);  
   
  rset   =   stmt.executeQuery("SELECT   DocumentID,DocumentContent   FROM   AttachedDocumentInfo");  
  BLOB   blob=null;  
  while   (   rset.next()   ){  
  //String   test   =   ((OracleResultSet)rset).getString(1);  
  //out.println("test="+test);  
  //blob   =   (oracle.sql.BLOB)(rset.getBlob(2));  
  blob   =   ((OracleResultSet)   rset).getBLOB   (2);  
  //blob   =   (java.sql.Blob)rset.getObject(2);  
  }  
   
  File   files   =   new   File("d:\\12345.doc");  
  System.out.println("FileToOracle   FileName="+files.getName());  
  fileinput   =   new   FileInputStream(files);  
  outstream   =   blob.getBinaryOutputStream();  
  int   chunk   =   blob.getChunkSize();  
  byte[]   buffer   =   new   byte[8*1024];  
  int   length   =   -1;    
  while   ((length   =   fileinput.read(buffer))   !=   -1){  
  outstream.write(buffer,   0,   length);  
  }  
  //myConn.commit();  
  fileinput.close();    
  outstream.close();    
   
   
  fileinput.close();  
  rset.close();  
  stmt.close();  
  }  
  catch(SQLException   se){System.out.println("SQL   Error:"+se);}  
  catch(Exception   E){  
  /*   Handle   exception   here.   */  
  System.out.println("Service   Error:   "+E);  
  }finally{  
  if(rset   !=   null){  
  try{  
  rset.close();  
  }catch(Exception   ignore){};  
  }  
  if(stmt   !=   null){  
  try{  
  stmt.close();  
  }catch(Exception   ignore){};  
  }  
  if(myConn   !=   null){  
  try{  
  myConn.close();  
  }catch(Exception   ignore){};  
  }  
  if(fileinput   !=   null){  
  try{  
  fileinput.close();  
  }catch(Exception   ignore){};  
  }  
  if(outstream   !=   null){  
  try{  
  outstream.close();  
  }catch(Exception   ignore){};  
  }  
  if(ps   !=   null){  
  try{  
  ps.close();  
  }catch(Exception   ignore){};  
  }  
  }  
  }  
  }  
  Top

相关问题

  • 急死了! oracle中long数据类型问题! 重酬!!!
  • JSP连ORACLE中文字符的显示问题!!!急死我了~~~
  • 急死我了!!!java与mysql的Blob问题 5~~~~~~~>_<~~~~~~~
  • 我快急死了!!关于连接远程oracle的问题求救
  • 一个oracle数据库连接的问题,我快急死了,帮帮忙吧!!!!
  • 现在急死了,下午招标要ORACLE相关证书,250高分求ORACLE证书扫描件!
  • 急死啦急死啦
  • 我快急死了!asp+oracle数据库中图片的存取与上传问题....
  • oracle的客户端要装些什么软件,才能访问到远程数据库,我急死了!!!
  • 急死我也!

关键词

  • oracle
  • jdbc
  • ps
  • sql
  • null
  • blob
  • fileinput
  • rset
  • myconn
  • outstream

得分解答快速导航

  • 帖主:yeyoujian

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo