简体   繁体   中英

resultSet.getTimeStamp() is not working

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

for resultset.getTimestamp("CURRENT_TIMESTAMP") it throws invalid column type exception

 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.

Any body help mee....

Your JDBC driver is really, REALLY old (like 10 years old).

The first thing you should try is using a current driver (ojdbc6.jar).

Edit: Here's a discussion on the oracle forums - it's definitely a driver bug fixed in Version 11.1.0.6.0 of the driver

What happens if you do

     String timeStamp = null;
     try {
        PreparedStatement ps = connection.prepareStatement("SELECT CURRENT_TIMESTAMP FROM DUAL");
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            timeStamp = rs.getString("CURRENT_TIMESTAMP");
        }

    } catch(Exception e){}

I have a feeling that CURRENT_TIMESTAMP in Oracle returns a TIMESTAMP WITH TIME ZONE data type that isn't mapped correctly in the JDBC driver. You may have to get it as a string and parse it manually.

As far as it working on some machines and not others, this might be due to the Timezones on the oracle installation and the timezones of the JVM being set up differently.

One note from the JavaDoc for getTimeStamp(int columnIndex ) (and other methods): @param columnIndex the first column is 1, the second is 2, ... , it's not 0-based, so getTimeStamp(1) would return the first column. Is that what you want? Or might your timestamp column be the second in the resultset?

Edit: I don't see you using getTimestamp(1) in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM