0

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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

4 Comments

it will throw the error on executing the PreparedStatement. getTimeStamp() is the next thing to execute after PreparedStatement.
Need more info; what kind of database is this? Also, the table you create is called "store" whereas in the query you use "csi". Are you sure the table "csi" exists and the query in consideration returns result when fired from a SQL editor?
Oh sorry it's a mistake i have created the table named csi it's not store.As i said earlier i am using oracle(10g exp).
SQLException supports chaining. Can you specifically catch SQLException and call its nextException() method to see if there are any other exceptions in there. Or better yet, use the iterator to print out all the chained exceptions. Read: download.oracle.com/javase/6/docs/api/java/sql/… . Also as already mentioned, use a real driver provided by oracle instead of the historical JDBC-ODBC bridge.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.