1

Am using jdk- 1.6, os- redhat 5, driver- class12.jar,(jar along with jdk lib) db-Oracle 10i

Code:-

  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;
    }

In some system its works fine ,in server only it throws following exception

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)

Only time related function of resultset is not working........(resultset.getTimestamp(),resultset.getDate()). But resultset.getString() works fine...

In java forum i got the answer it is because of Difference in JRE Time zone setup with oracle return timezone setup... Is it correct or not..... Or how can i solve this............ Please help me.............

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
user735936
  • 29
  • 3
  • 7
  • possible duplicate of [ResultSet.getTimeStamp(1) is not work in some systems](http://stackoverflow.com/questions/5858507/resultset-gettimestamp1-is-not-work-in-some-systems) – jmj May 06 '11 at 06:03
  • You keep posting the **exact same question** with varying levels of detail, please stop that! Instead, edit your original question when you find some additional information. – Joachim Sauer May 06 '11 at 06:08
  • `catch(Exception e){}` Don't do this. Your method already throws `SQLException` so there is no need to even use a try/catch block, and if you did need to, you should handle it properly. The only reason you encountered this error is because Sun were clever enough to foresee people misusing exception-catching like you have, and made `Error` extend `Throwable` instead of `Exception`. If you had caught this error, you would never have known about it. – BoffinBrain May 06 '11 at 09:48

1 Answers1

0

If the timestamp is represented as a timestamp - that is, the number of millis after Jan 1 1970 then perhaps you get get it with getLong(..). Even Long.parseLong(getString()) would do in that case.

If the string returned by the database is actually a formatted date string, then check the format and parse it using SimpleDateFormat.

I agree this is a bit of 'hackery', so first try to upgrade your JDBC driver.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140