user735936
user735936

Reputation: 29

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....

Upvotes: 0

Views: 4245

Answers (3)

Michael Borgwardt
Michael Borgwardt

Reputation: 346327

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

Upvotes: 2

DaveH
DaveH

Reputation: 7335

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.

Upvotes: 1

Thomas
Thomas

Reputation: 88707

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.

Upvotes: 0

Related Questions