[英]JDBC-ODBC SQLException:General Error
I am using JDK 1.6. 我正在使用JDK 1.6。 With that I want to connect to an Access database.
这样,我想连接到Access数据库。 For that I've registered a System DNS & trying to connect that database using JDBC-ODBC connection.
为此,我已经注册了系统DNS,并尝试使用JDBC-ODBC连接来连接该数据库。
When I connect it & test it by firing a simple query to check whether connection has been established properly or not. 当我连接它并通过触发一个简单的查询来测试它以检查连接是否正确建立时进行测试。
Here is my code snippet to execute query. 这是我执行查询的代码段。
public void testConnection() {
Connection conn = DBUtil.getConnection();
Statement stmt = null;
try {
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT id FROM inventory");
System.out.println("Connection Successful");
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (stmt != null) {
stmt.close();
}
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
I am calling testConnection()
method more than once. 我
testConnection()
调用testConnection()
方法。
Now the matter is that the query works fine for the first time, rest of three times it gives error, which is mentioned below. 现在的问题是,查询第一次可以正常工作,其余三次给出错误,下面将进行介绍。
java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.throwGenericSQLException(JdbcOdbc.java:7086)
at sun.jdbc.odbc.JdbcOdbc.SQLAllocStmt(JdbcOdbc.java:173)
at sun.jdbc.odbc.JdbcOdbcConnection.prepareStatement(JdbcOdbcConnection.java:465)
at sun.jdbc.odbc.JdbcOdbcConnection.prepareStatement(JdbcOdbcConnection.java:443)
Please let me know where the thing goes wrong? 请让我知道问题出在哪里?
Note : I am running the program on Windows 7, 64 bit variant. 注意 :我正在Windows 7(64位版本)上运行该程序。 Registered datasource using 32 bit driver on local machine (From path:
%windir%/SYSWOW64/odbcad32.exe
) 使用本地计算机上的32位驱动程序注册的数据源(来自路径:
%windir%/SYSWOW64/odbcad32.exe
)
I am really not sure about this, but try something like this: 我真的不确定,但是尝试这样的事情:
public void testConnection() {
Connection conn = null;
PreparedStatement pre =null;
ResultSet rs =null;
try {
conn = DBUtil.getConnection();
PreparedStatement pre = conn.prepareStatement("select id from inventory");
rs = pre.executeQuery();
System.out.println("Connection Successful");
} catch (Exception ex) {
ex.printStackTrace();
} finally {
conn.close();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.