代码:

 OracleCachedRowSet rowSet =  new OracleCachedRowSet();
 ResultObject obj = new ResultObject(0,null);
 PreparedStatement pstat = connection.prepareStatement(strQry);
 rowSet.populate(pstat.executeQuery());
 rowSet.beforeFirst();

 while(rowSet.next()){
      System.out.println("Conference name "+rowSet.getString(1));
      System.out.println("StartTime "+rowSet.getTimestamp(5)) ;
 }


当我运行以上代码时,出现如下错误:

java.sql.SQLException: Invalid column type
    at oracle.jdbc.rowset.OracleCachedRowSet.getTimestamp(OracleCachedRowSet.java:4399)
    at test.Test.main(Test.java:102)


如果我使用ResultSet而不是OracleCachedRowSet,同样的东西也可以正常工作(检查下面的正确代码)

  PreparedStatement pstat = connection.prepareStatement(strQry);
  ResultSet rset =   pstat.executeQuery();
  while(rset.next()){
        System.out.println("Conference name "+rset.getString(1));
        System.out.println("StartTime "+rset.getTimestamp(5)) ;
  }


有什么办法可以使用getTimestamp()OracleCachedRowSet吗?

最佳答案

我们可以通过以下方法实现定义的目标:

java.util.Date date = new java.util.Date(((oracle.sql.TIMESTAMP)rSet.getObject(5)).timestampValue().getTime())

07-24 13:48