I have a simple question... Why this code below is not working?
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 :)
As @krokodilko suggests, I will post here my comment as an answer:
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:
SELECT TO_CHAR(SYSTIMESTAMP, 'DD/MM/YYYY HH24:MI:SS.SSXFF TZR') FROM DUAL
And then I had to do a parse to 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.