oracle java.sql.SQLRecoverableException:没有更多的数据要从套接字读取
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11522919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.sql.SQLRecoverableException: No more data to read from socket
提问by hli
I have a database table in oracle which has a column of type DATE. It looks like the table below
我在 oracle 中有一个数据库表,它有一列类型为 DATE。它看起来像下表
TABLE1
表格1
ID PRODUCT_NAME ITEM_CNT ENTERED_DATE
1 prod1 500 2012-07-01
2 prod2 1000 2012-06-30
in my java code, I want to get the total item_cnt for a certain date range. here is the code sample
在我的 java 代码中,我想获取某个日期范围内的 item_cnt 总数。这是代码示例
String sql = "select sum(item_cnt) from table1 where entered_date between ? and ?";
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rset = null;
try{
conn = getConnection(url, user, passwd);
pstmt = conn.prepareStatement(sql);
pstmt.setDate(1, java.sql.Date.valueOf(from_date)); //from_date is a string of "yyyy-mm-dd"
pstmt.setDate(2, java.sql.Date.valueOf(to_date)); //to_date is a string of "yyyy-mm-dd"
rset = pstmt.executeQuery();
....
}catch(SQLException e){
//do something
} finally{
//clean up
}
This code was running fine for a while until three days ago, I start getting the following exception at line pstmt.executeQuery();
这段代码运行良好,直到三天前,我开始在 pstmt.executeQuery(); 行收到以下异常;
java.sql.SQLRecoverableException: No more data to read from socket
at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1157)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:290)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:884)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1289)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3628)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1493)
I tried to search for answers but couldn't find anything that really explains it. then I changed my sql query to
我试图寻找答案,但找不到任何能真正解释它的东西。然后我将我的 sql 查询更改为
"select sum(item_cnt) from table1 where entered_date between to_date(?, 'yyyy-mm-dd') and to_date(?, 'yyyy-mm-dd')";
and instead of setting date, I changed the prepared statement to the following
我没有设置日期,而是将准备好的语句更改为以下内容
pstmt.setString(1, from_date);
pstmt.setString(2, to_date);
Then the exception is gone.
然后异常消失了。
Another confusion is, when I populate my table, I am still using the following
另一个困惑是,当我填充表格时,我仍在使用以下内容
pstmt.setDate(1, java.sql.Date.valueOf(date)); //date is a string of format "yyyy-mm-dd"
and it is still working. only the select statement was giving me exceptions.
它仍在工作。只有 select 语句给了我例外。
Now everything is working but I really want to know why. Anyone knows?
现在一切正常,但我真的很想知道为什么。有谁知道?
I did upgrade my java to 1.7.0_03-b05 recently. and I am using ojdbc6.jar. The oracle is 11g. Could this be the driver's problem? is ojdbc7 out?
我最近确实将我的 java 升级到了 1.7.0_03-b05。我正在使用 ojdbc6.jar。神谕是11g。会不会是司机的问题?ojdbc7 出来了吗?
回答by emarshah
I was facing this exception while working over JDBC with IBM WAS 7.0, I had performed a JCA lifecycle management operation on data source. Which is like controlling the runtime status of the data source. Purgeremoves the contents of connection pool for the data source. However, in WAS this purging the pool will not affect the ongoing transactions. Check on your side.
我在使用 IBM WAS 7.0 通过 JDBC 工作时遇到了这个异常,我对数据源执行了 JCA 生命周期管理操作。这就像控制数据源的运行时状态。Purge删除数据源连接池的内容。但是,在 WAS 中,这种清除池不会影响正在进行的事务。检查在你身边。
Another thing which I performed was; the disk space was full on directory where Oracle was installed, I added extra space over that.
我表演的另一件事是;安装 Oracle 的目录上的磁盘空间已满,我在其上添加了额外的空间。
回答by Shilpa
As a best practice, I stay away from java.sql.Date class and use to_date() and to_char() functions while dealing with Dates in Java with Oracle.
作为最佳实践,在使用 Oracle 处理 Java 中的日期时,我远离 java.sql.Date 类并使用 to_date() 和 to_char() 函数。