`
kalogen
  • 浏览: 880280 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Some exceptions in Oracle

阅读更多
Gotchas With Oracle Jdbc Driver


          1- java.sql.SQLException: ソケットから読み込むデータはこれ以上ありません(java.sql.SQLException: No more data to read from socket)
           Driver Version: 9i.*    or 10g.*

           该异常通常是因为使用了连接池,当从连接池取得的connection失效或者超时的时候,使用这个连接来进行数据库操作就会抛出以上异常。
           解决方法就是让数据库连接池在给你返回connection之前,检查该connnection是否超时或者失效,如果是,则evict这个connection,并返回一个可用的connection。
           以DBCP为例,做如下配置即可解决问题:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="url">
   <value>${jdbc.url}</value>
  </property>
  <property name="driverClassName">
   <value>${jdbc.driver}</value>
  </property>
  <property name="username">
   <value>${jdbc.username}</value>
  </property>
  <property name="password">
   <value>${jdbc.password}</value>
  </property>
  <property name="testOnBorrow">
   <value>true</value>
  </property>
  <property name="testOnReturn">
   <value>true</value>
  </property>
  <property name="testWhileIdle">
   <value>true</value>
  </property>
  <property name="minEvictableIdleTimeMillis">
   <value>180000</value>
  </property>
  <property name="timeBetweenEvictionRunsMillis">
   <value>360000</value>
  </property>
  <property name="validationQuery">
   <value>SELECT 1 FROM SYS.DUAL</value>
  </property>
  <property name="maxActive">
   <value>100</value>
  </property>
</bean>
          另外,你也可以参考这里:http://www.websina.com/bugzero/errors/oracle-SQLException.html
          转贴: Oracle SQLException: No more data to read from socket
java.sql.SQLException: No more data to read from socket 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.MAREngine.unmarshalUB1(MAREngine.java:963)
at oracle.jdbc.ttc7.MAREngine.unmarshalSB1(MAREngine.java:893)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:375)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1894)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1094)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2132)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2015)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2877)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)

This error most likely occurs in applications that use a database connections pool. When the application checked out a connection that has been timed out or has been staled, and used it to connect to the database, this error occurs.
You may need start your Oracle database server as well as your Java application. In a better designed system, however, the staled connection should be cleared out and a new connection should be establised automatically.
--------------------------------------------------
          2-ORA-17004: Invalid column type  (java.sql.SQLException: 列の型が無効です。)         Driver Version: 9i.*

          该异常初次出现在使用spring+iBatis的程序中,后来通过检查出现错误的字段和SQLMAP的参考文档,才发现问题之所在。
          如果你使用iBatis,那从他的SqlMap参考文档中应该找到以下文字,当你看到他们的时候,你就发现了通向成功之门的钥匙,呵呵
          Note! Most drivers only need the type specified for nullable columns.  Therefore, for such drivers you only
need to specify the type for the columns that are nullable. 
          Note! When using an Oracle driver, you will get an “Invalid column type” error if you attempt to set a null
value to a column without specifying its type. 
          也就是说,当某个column允许为空,而你传的参数对应该column的值也为null的时候,对于oracle的驱动来说,这个异常是铁定的了。

          解决方法,可以通过iBatis的parameterMap,指定parameter元素的jdbcType和nullValue来解决;如果你没有使用iBatis,那你可以通过检查参数,如果他对应的列为可以为空,而当前值恰好就是空的时候,为他设置一个不是空的值即可。
--------------------------------------------------
           3-java.sql.SQLException: OALL8矛盾した状態にあります;(java.sql.SQLException: OALL8 is in an inconsistent state.)

           该异常在我们的程序中通常是在第一个异常出现之后出现,但也不尽然,该异常搜遍网上也找不到合理的解释,只有以下信息可能会有用一些(from   http://forums.oracle.com/forums/thread.jspa?messageID=1275383):
This is known to occur under when you are using too big an array size. How big your array can be depends on the length of each record and the Driver/Database combination. If you exceed the maximum size you will get the "OALL8" SQLException and your connection object may become unusable.

This message is also created if you are using the following:

9.0.1 Database
10.1.0 JDBC Driver
Generated Code that passes in an ARRAY or VARRAY of VARCHAR2 as a Parameter

            或者(from http://opensource.atlassian.com/projects/spring/browse/SPR-1545?decorator=none&view=rss):
[SPR-1545] Oracle error 17447 should result in a DataAccessResourceFailureException
Oracle error 17447 is currently an unmapped exception but it should be a DataAccessResourceFailureException.  This error occurs when a JDBC connection has become corrupted, usually because of failure to properly close a connection before returning the connection to the connection pool.  Here is the error message:

SQL state [null]; error code [17447]; OALL8 is in an inconsistent state; nested exception is java.sql.SQLException: OALL8 is in an inconsistent state
    java.sql.SQLException: OALL8 is in an inconsistent state

This is a kind of "oh crap, something bad happened and it's not really your fault" exception in Oracle.  A few causes of this message are suggested in my searches on Google, including (see http://forums.oracle.com/forums/thread.jspa?threadID=274018&tstart=0):
- use of Oracle 10g JDBC drivers to connect to Oracle 9 databases
- using too big an array size (9.0.1 Database, 10.1.0 JDBC Driver and Generated Code that passes in an ARRAY or VARRAY of VARCHAR2 as a Parameter )

In any case, after this exception is thrown the connection is corrupted and unusable, hence why I advocate this exception be mapped to a DataAccessResourceFailureException

            解决方法,我也不知道,呵呵,反正调整了第一个问题之后,这个异常再没有在我们的程序中出现。
--------------------------------------------------
分享到:
评论

相关推荐

    Foundations for Analytics with Python O-Reilly-2016-Clinton W. Brownley

    This chapter also discusses programming concepts such as control flow, functions, and exceptions, as these are important elements for including business logic in your code and gracefully handling ...

    mysql 5.1.59

    Therefore there are special exceptions to the terms and conditions of the GPLv2 as applied to these client libraries, which are identified and described in more detail in the FOSS License Exception...

    Progress/OpenEdge语言手册

    With few exceptions, all keywords of the language appear in all UPPERCASE, using a font that is appropriate to the context. All other alphabetic language content appears in mixed case. For the latest...

    java7帮助文档

    Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking Java Virtual Machine Java Virtual Machine Support for Non-Java Languages: Java SE 7 introduces a new JVM ...

    Java-jdk-1.7.0

    JDK(Java Development Kit)是Oracle公司提供的一个用于Java编程的基础平台,它包含了Java编译器、Java运行环境、调试工具和其他必要的API文档。在Java 1.7.0这个版本中,开发者可以享受到许多新特性以及性能优化。...

    PL/SQL 基础学习材料

    PL/SQL是Oracle数据库系统中的一个强类型编程语言,它扩展了SQL,使得开发者能够编写复杂的存储过程、函数和触发器。以下是对标题和描述中所提到的知识点的详细解释: 1. **声明变量 (Declaring Variables)** 在...

    jdk-7u80-windows-x64.rar

    JDK 1.7,也称为Java 7,是Oracle公司发布的一个重要版本,它引入了许多新特性,优化了性能,并修复了大量已知问题。在"jdk-7u80-windows-x64.rar"这个压缩包中,包含的是适用于Windows 64位操作系统的JDK 7更新80...

    jdk7安装程序

    // some code that may throw exceptions } catch (IOException | SQLException e) { // handle both types of exceptions here } ``` 此外,JDK7引入了“开关”语句支持字符串(switch on String),这使得...

    JDK1.7与环境配置

    // handle exceptions } ``` 2. **字符串转换为数值类型**:新增了`Integer`类中的`parseInt`方法来解析字符串,使得将字符串转换为整型更加方便。 ```java int value = Integer.parseInt("123"); ``` 3. ...

    java jdk1.7

    // some code that may throw exceptions } catch (IOException | EOFException e) { // handle both exceptions } ``` 这种改进使得代码更加简洁和易于维护。 ##### 2. **自动资源管理(try-with-resources)**...

    jdk7源代码

    JDK 7,也被称为JDK 1.7,是Oracle公司发布的一个重要版本,它引入了许多新特性,优化了性能,并修复了大量的bug。通过深入学习JDK 7的源代码,开发者可以更好地理解Java语言的工作原理,提高编程技能,并对新旧版本...

Global site tag (gtag.js) - Google Analytics