1

我正在使用 jdk- 1.6,os-redhat 5,驱动程序-class12.jar,(jar 连同 jdk lib)db-Oracle 10i

代码:-

  public Timestamp getCurrentTimeStamp(Connection connection) throws SQLException {
        Timestamp timeStamp = null;
        try {
            PreparedStatement ps = connection.prepareStatement(" SELECT CURRENT_TIMESTAMP FROM DUAL");
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                timeStamp = rs.getTimestamp("CURRENT_TIMESTAMP");
            }

        } catch(Exception e){}
        return timeStamp;
    }

在某些系统中它工作正常,仅在服务器中它抛出以下异常

java.sql.SQLException: Invalid column type
        at oracle.jdbc.dbaccess.DBError.
throwSqlException(DBError.java:189)
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:231)
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:294)
        at oracle.jdbc.driver.OracleStatement.getTimestampValue(OracleStatement.java:4627)
        at oracle.jdbc.driver.OracleResultSetImpl.getTimestamp(OracleResultSetImpl.java:409)
        at oracle.jdbc.driver.OracleResultSet.getTimestamp(OracleResultSet.java:1649)
        at org.apache.tomcat.dbcp.dbcp.DelegatingResultSet.getTimestamp(DelegatingResultSet.java:262)
        at myutils.FoursplUtils.getCurrentTimeStamp(FoursplUtils.java:131)
        at NewServlet.processRequest(NewServlet.java:44)
        at NewServlet.doGet(NewServlet.java:74)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
        at java.lang.Thread.run(Thread.java:619)

只有结果集的时间相关功能不起作用............(resultset.getTimestamp(),resultset.getDate())。但是 resultset.getString() 工作正常......

在java论坛中我得到了答案,这是因为JRE时区设置与oracle返回时区设置的差异......它是否正确......或者我该如何解决这个............ ... 请帮我.............

4

1 回答 1

0

如果时间戳表示为时间戳 - 即 1970 年 1 月 1 日之后的毫秒数,那么您可能会得到它getLong(..)。即使Long.parseLong(getString())在那种情况下也会这样做。

如果数据库返回的字符串实际上是格式化的日期字符串,则检查格式并使用SimpleDateFormat.

我同意这有点“骇人听闻”,所以首先尝试升级您的 JDBC 驱动程序。

于 2011-05-06T06:10:37.007 回答