论坛首页 Java企业应用论坛

『出错』Struts1.2+spring1.2.1+hibernate3+oracle9i 处理Bl...

浏览 4164 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2005-08-11  
软件环境:
Struts1.2+spring1.2.1+hibernate3,数据库使用oracle9i,jdbc驱动使用"ojdbc14-9.2.0.6.jar"。服务器为:jboss4.0.2    jdk1.5
配置文件:
hbm.xml中Photo字段:
<property name="photo" type="java.sql.Blob">
      <column name="PHOTO" />
</property>
程序:
    String fileName = photoFile;
   Photo photo = new Photo();
    photo.setPhoto(Hibernate.createBlob(new byte[1]));
    Long a = new Long(25);
    photo.setCandiid(a);
    try {
      getHibernateTemplate().saveOrUpdate(photo);
      getHibernateTemplate().flush();
      getHibernateTemplate().refresh(photo, LockMode.UPGRADE);
     BLOB blob = (BLOB) ((SerializableBlob) photo.getPhoto()).getWrappedBlob();
      OutputStream out = blob.getBinaryOutputStream();
      FileInputStream fin = new FileInputStream(fileName);
      byte[] buf = new byte[10240];
      int len;
      while ((len = fin.read(buf)) > 0) {
        out.write(buf, 0, len);
      }
      fin.close();
      out.close();
    } catch (SQLException e) {
      e.printStackTrace();
    } catch (FileNotFoundException e1) {
      e1.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
错误提示信息:
使用junit测试时没有使用jboss的连接池,执行到OutputStream out = blob.getBinaryOutputStream();时出现错误:
java.sql.SQLException: 必须登录到服务器
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1160)
at oracle.jdbc.ttc7.TTC7Protocol.assertLoggedIn(TTC7Protocol.java:2270)
at oracle.jdbc.ttc7.TTC7Protocol.getLobChunkSize(TTC7Protocol.java:3058)
at oracle.sql.LobDBAccessImpl.getChunkSize(LobDBAccessImpl.java:334)
at oracle.sql.BLOB.getChunkSize(BLOB.java:484)
at oracle.sql.BLOB.getBufferSize(BLOB.java:521)
at oracle.sql.BLOB.getBinaryOutputStream(BLOB.java:419)
at com.dareway.wmp.dao.hibernate.PhotoDAOHibernate.savePhoto(PhotoDAOHibernate.java:90)
at com.dareway.wmp.dao.PhotoDAOTest.testSave(PhotoDAOTest.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
在服务器上运行,此时使用jboss的服务器,异常信息:
Unhandled Exception thrown: class java.lang.ClassCastException
出现在:BLOB blob = (BLOB) ((SerializableBlob) photo.getPhoto()).getWrappedBlob();
你的分析:
没有想明出错原因,有哪位遇到此类问题啊?有无解决方案?
   发表时间:2005-08-15  
spring 中有相应的辅助类

用10g 的JDBC
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics