简体   繁体   English

获取时间戳结果为java.sql.SQLException:一般错误

[英]Getting Timestamp results in java.sql.SQLException: General error

I have a problem with fetching a timestamp from an Oracle database. 从Oracle数据库中获取时间戳时遇到问题。

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. 看起来JDBC ODBC桥驱动程序不了解如何为Oracle 10g数据库创建预准备语句。

Just do not use that lousy driver. 只是不要使用那个糟糕的司机。 You're not the first one who encounters DB-specific problems with it. 你不是第一个遇到DB特定问题的人。 Use a real Oracle JDBC driver instead. 请改用真正的 Oracle JDBC驱动程序

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. 查看ResultSet对象的getTimestamp方法以满足您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM