0

所以我正在尝试连接到数据库文件 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

是什么导致了问题?提前感谢您的宝贵时间。

4

1 回答 1

2

尝试下载http://sourceforge.net/projects/ucanaccess/files/UCanAccess-2.0.9.5-bin.zip/download并配置您的构建路径,将 jar 文件从下载的文件中添加到 lib 文件夹中。

@编辑

您的问题可能与项目中缺少依赖项有关。驱动程序类 (net.ucanaccess.jdbc.UcanaccessDriver) 可能不存在于您的构建路径中。更改异常捕获以获得更好的调试:

System.out.println(ex.getMessage());

ex.printStackTrace();
于 2015-06-07T18:37:05.420 回答