2

我遇到了 UCanAccess 驱动程序的问题,即当我尝试使用以下代码连接到数据库时

public static void main(String[] args) {
    //establish connection with database in order to execute sql queries
    try {
        conn = DriverManager.getConnection("jdbc:ucanaccess://H:\\IT_PAT_Program_LOCALONLY\\IT_Pat_Database.accdb;showschema=true");
        System.out.println("Connection Established");
    } catch (SQLException ex) {
        System.out.println("Could Not Connect to database\n"+ex);
    }
    //closes the database connection at program shutdown
    Runtime.getRuntime().addShutdownHook(new Thread() {
        public void run() {
            try {
                conn.close();
                System.out.println("Shutdown Succesful");
            } catch (SQLException ex) {
                System.out.println("An exception occured\n"+ex);
            }
        }
    });
}

我遇到以下错误:

Could Not Connect to database
net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.0 invalid authorization specification - not found: Admin

数据库也作为持久性单元连接,但是由于我不知道有任何方法可以从代码中使用它(谷歌没有帮助),这种方法似乎是我唯一的选择。

4

1 回答 1

1

我们无法看到您在代码中进行授权的位置。

  • 用户?
  • 密码 ?

Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conn=DriverManager.getConnection(
                                "jdbc:ucanaccess://<mdb or accdb file path>",user, password);
于 2015-08-19T17:56:15.593 回答