简体   繁体   中英

Getting Timestamp results in java.sql.SQLException: General error

I have a problem with fetching a timestamp from an Oracle database.

The table is created as follows:

create table csi(start_time timestamp);

Then I selected the value as follows:

import java.sql.*;

public class hel
{
    public static void main(String args[])
    {
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con=DriverManager.getConnection("jdbc:odbc:mohit","system","rock");
            PreparedStatement ps=con.prepareStatement("select * from csi");
            ResultSet rs=ps.executeQuery();
            while(rs.next())
            {
                //System.out.println(rs.getString(4));
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

    }
}

But it throws the following exception:

java.sql.SQLException: General error
     at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
     at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
     at sun.jdbc.odbc.JdbcOdbc.SQLPrepare(Unknown Source)
     at sun.jdbc.odbc.JdbcOdbcConnection.prepareStatement(Unknown Source)
     at sun.jdbc.odbc.JdbcOdbcConnection.prepareStatement(Unknown Source)
     at hel.main(hel.java:10)

How is this caused and how can I solve it?

Here's a simple translation of the first few lines of the trace (read comments from bottom to top):

java.sql.SQLException: General error
  at sun.jdbc.odbc.JdbcOdbc.createSQLException         // I have to create and throw the SQL exception!
  at sun.jdbc.odbc.JdbcOdbc.standardError              // Uuuh, something failed?
  at sun.jdbc.odbc.JdbcOdbc.SQLPrepare                 // Let's start preparing it.
  at sun.jdbc.odbc.JdbcOdbcConnection.prepareStatement // Ah, a prepared statement is been requested.

It look like that the JDBC ODBC bridge driver doesn't understand how to create prepared statements for an Oracle 10g database.

Just do not use that lousy driver. You're not the first one who encounters DB-specific problems with it. Use a real Oracle JDBC driver instead.

Please post the exact error. Also, why are you trying to retrieve a string from something which contain a timestamp? Look into the getTimestamp method of the ResultSet object for your needs.

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