开发者

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 excepti开发者_JAVA技巧on:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜