javams-accessnetbeansucanaccesspersistence-unit

"Invalid authorization specification" error on UCanAccess connect


I am having a problem with the UCanAccess driver namely that when I attempt to connect to a database using the following code

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);
            }
        }
    });
}

I am met with the following error:

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

The database is also connected as a persistence unit however since I'm unaware of any way to make use of that from within the code (Google has been no help) this method seems to be my only option.


Solution

  • We can not see where you are doing the authorization in your code.


    Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
    Connection conn=DriverManager.getConnection(
                                    "jdbc:ucanaccess://<mdb or accdb file path>",user, password);