I have a simple question... Why this code below is not working?
- JDK version: 1.8.0_92
- Oracle DB version: 11.2.0.1.0
Oracle JDBC driver: ojdbc6.jar ---> I could not find this java code source :(
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 "java.sql.SQLException: Invalid SQL type for column"
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:
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?
I start to think that it is a bug of oracle's jdbc implementation...
Sorry about my bad english :)