2

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.

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418

1 Answers1

2

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

  • user ?
  • password ?

Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conn=DriverManager.getConnection(
                                "jdbc:ucanaccess://<mdb or accdb file path>",user, password);
moskito-x
  • 11,832
  • 5
  • 47
  • 60
  • there is no authorisation its a normal non-password protected microsoft access database. should i just put "" for both then? – kyle hendry Aug 20 '15 at 09:33
  • How you connect with netbeans ? – moskito-x Aug 20 '15 at 10:17
  • 1
    @kylehendry - *"should i just put "" for both then?"* - Try that, at least. It sounds like you have something configured somewhere to use "Admin" as a user name and UCanAccess (HSQLDB, actually) does not accept it. – Gord Thompson Aug 20 '15 at 13:51
  • For MS Database if there is no user, `Admin` is generated. Try `"jdbc:ucanaccess://","Admin","")` – moskito-x Aug 20 '15 at 13:54
  • 2
    putting the empty strings seems to have worked thanks. accepted answer thanks everyone for the help – kyle hendry Aug 20 '15 at 15:25