简体   繁体   English

Oracle 1.8 CachedRowSet.populate错误,其中从双选择systimestamp

[英]Oracle 1.8 CachedRowSet.populate error where select systimestamp from dual

I have a simple question... Why this code below is not working? 我有一个简单的问题...为什么下面的代码不起作用?

  • JDK version: 1.8.0_92 JDK版本:1.8.0_92
  • Oracle DB version: 11.2.0.1.0 Oracle DB版本:11.2.0.1.0
  • Oracle JDBC driver: ojdbc6.jar ---> I could not find this java code source :( Oracle JDBC驱动程序:ojdbc6.jar --->我找不到此Java代码源:(

     String SQL = "select systimestamp from dual"; Statement statement = null; ResultSet rs = null; try { statement = getConnection(name).createStatement(); if (statement != null) { rs = statement.executeQuery(SQL); } // Need to use a CachedRowSet that caches its rows in memory, which // makes it possible to operate without always being connected to // its data source CachedRowSet rowset = new CachedRowSetImpl(); rowset.populate(rs); return rowset; } catch (SQLException ex) { throw new DatabaseException(ex.getMessage(), ex); } finally { safeCloseResultSet(rs); safeCloseStatement(statement); } 

The stack trace: 堆栈跟踪:

java.sql.SQLException: Invalid SQL type for column
at javax.sql.rowset.RowSetMetaDataImpl.checkColType(RowSetMetaDataImpl.java:114)
at javax.sql.rowset.RowSetMetaDataImpl.setColumnType(RowSetMetaDataImpl.java:459)
at com.sun.rowset.CachedRowSetImpl.initMetaData(CachedRowSetImpl.java:761)
at com.sun.rowset.CachedRowSetImpl.populate(CachedRowSetImpl.java:639)

The line " rowset.populate(rs); " throws a "j ava.sql.SQLException: Invalid SQL type for column " rowset.populate(rs); ”行抛出“ j ava.sql.SQLException:列 ”的SQL类型无效

The error occurs when I try to execute the query: 当我尝试执行查询时发生错误:

select systimestamp from dual

But if I use the code below instead of " rowset.populate(rs); ", it works: 但是,如果我使用下面的代码而不是“ rowset.populate(rs); ”,它将起作用:

rs.getTimestamp(1)

And if I try to execute the query below, everything works well: 而且,如果我尝试执行以下查询,则一切正常:

select sysdate from dual

So, how can I use the rowset.populate(rs) to get the syscurrenttimestamp ? 那么,如何使用rowset.populate(rs)获取syscurrenttimestamp

I start to think that it is a bug of oracle's jdbc implementation... 我开始认为这是Oracle的jdbc实现的错误...

Sorry about my bad english :) 对不起,我的英语不好:)

As @krokodilko suggests, I will post here my comment as an answer: 正如@krokodilko所建议的那样,我将在此处发布我的评论作为答案:

I ended up solving the problem with a palliative solution. 我最终以姑息解决方案解决了这个问题。 Instead of performing the query to return a TIMESTAMP, I made it to return a STRING: 我没有执行查询来返回TIMESTAMP,而是让它返回了STRING:

SELECT TO_CHAR(SYSTIMESTAMP, 'DD/MM/YYYY HH24:MI:SS.SSXFF TZR') FROM DUAL

And then I had to do a parse to TIMESTAMP. 然后我必须对TIMESTAMP进行解析。 I know that it's ugly, but is just until we find a correct solution. 我知道这很丑陋,但是直到我们找到正确的解决方案为止。 I still have hope that someone will help us with this matter. 我仍然希望有人会帮助我们解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM