user925689
user925689

Reputation: 21

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?

Upvotes: 0

Views: 719

Answers (2)

BalusC
BalusC

Reputation: 1108722

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.

Upvotes: 2

Sanjay T. Sharma
Sanjay T. Sharma

Reputation: 23208

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.

Upvotes: 0

Related Questions