我正在尝试从.mdb数据库中获取一些数据,这是代码:
package com.java.myapp;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
public class MyClass {
public static void main(String[] args) {
Connection connect = null;
Statement s = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connect = DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};" +
"DBQ=mydatabase.mdb;uid=;pwd=;");
s = connect.createStatement();
String Name = "Win";
String sql = "SELECT * FROM customer WHERE Name LIKE '%" + Name + "%' ";
ResultSet rec = s.executeQuery(sql);
while((rec!=null) && (rec.next()))
{
System.out.print(rec.getString("CustomerID"));
System.out.print(" - ");
System.out.print(rec.getString("Name"));
System.out.print(" - ");
System.out.print(rec.getString("Email"));
System.out.print(" - ");
System.out.print(rec.getString("CountryCode"));
System.out.print(" - ");
System.out.print(rec.getFloat("Budget"));
System.out.print(" - ");
System.out.print(rec.getFloat("Used"));
System.out.println("");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
s.close();
connect.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
但是我收到了这个错误:
Unable to load JdbcOdbc library:java.sql.SQLException: Unable to load JdbcOdbc library
Exception:java.sql.SQLException: No suitable driver
Exception:java.lang.NullPointerException
我在AIX中尝试这个jar,数据库没有密码。 好像我错过了一个图书馆,但我不知道那个图书馆。 谢谢你的帮助。