所以我试图连接到数据库文件MSAccess。这是代码:
public class DAOCarLoader implements CarLoader {
List < Owner > owners = new ArrayList < Owner > ();
Connection con;
Statement st;
ResultSet rs;
public DAOCarLoader() {
loadData1();
}
public void loadData1() {
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
String db = "jdbc:ucanaccess://C:/Users/Anjelo/Desktop/CarTable2.mdb";
con = DriverManager.getConnection(db);
st = con.createStatement();
String sql = "select * from Table1";
rs = st.executeQuery(sql);
while (rs.next()) {
String brand = rs.getString("CarBrand");
String carnumber = rs.getString("CarNum");
int year = rs.getInt("CarYear");
String fname = rs.getString("OwnerName");
String egn = rs.getString("OwnerEGN");
System.out.println("TEST");
System.out.println(brand + " " + carnumber + " " + year + " " + fname + " " + egn);
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
@Override
public List < Owner > loadData() {
// TODO Auto-generated method stub
return null;
}
public static void main(String[] args) {
new DAOCarLoader();
}
}
但每次我运行程序时,控制台中唯一显示的是:
net.ucanaccess.jdbc.UcanaccessDriver
导致问题的原因是什么?提前感谢您的时间。
答案 0 :(得分:2)
尝试下载http://sourceforge.net/projects/ucanaccess/files/UCanAccess-2.0.9.5-bin.zip/download并配置构建路径,将jar文件从下载的文件添加到lib文件夹中。
@Edit
您的问题可能与项目中缺少的依赖项有关。您的构建路径中可能不存在驱动程序类(net.ucanaccess.jdbc.UcanaccessDriver)。更改异常捕获以获得更好的调试:
System.out.println(ex.getMessage());
到
ex.printStackTrace();