4

i am trying to fill a table from a database using ucanacces but it gives me the following error and i don't understand why, upon googling this error most people mention something about a username and password but i don't see how that is relevant as i don't use a username and password throughout the application.

Error (this is the full error, i don't know why it just ends after the ':'):

net.ucanaccess.jdbc.UcanaccessSQLException: invalid authorization specification - not found: 

Code:

final static String DBPAD = "src/Attachments/Database SOFO.mdb";
final static String DB = "jdbc:ucanaccess://" +DBPAD;

public void HaalKlantNamen(){
        Connection con;
        Statement s;
        ResultSet rs = null;
        DefaultTableModel table = (DefaultTableModel) NewOrder.table.getModel();

        try {
            con = DriverManager.getConnection( DB ,"",""); 
            s = con.createStatement();
            rs = s.executeQuery("select * from Item"); 

            if (rs != null) 
                while ( rs.next() ) {
                    String[] product = new String[2];
                    product[0] = rs.getString("ItemSoort");                    
                    product[1] = rs.getString("Naam");                    
                    table.addRow(product);
                }
            s.close();
            con.close();
        } 
        catch (SQLException e) {
            System.out.println("Error2: " + e);
        }
    }
Bart
  • 41
  • 3
  • Try running `console.bat` or `console.sh` (found in the same folder as the ucanaccess-2.0.9.4.jar file). When prompted, give it the full path to the database in question and see if the results provide any more information. – Gord Thompson Apr 26 '15 at 15:05
  • Also, please [edit] your question to show us your connection URL (in `DB`). – Gord Thompson Apr 26 '15 at 15:12
  • It gives me a list of things it can load: http://gyazo.com/620b31fdb776b7f72b2254cea5d7f30b i'm pretty sure it can access the database as it works in other parts of the application – Bart Apr 26 '15 at 15:21
  • is the space in the file name problematic? – jtahlborn Apr 26 '15 at 15:23
  • as mentioned in my previous comment, it shouldn't be as the database connection works in other parts of the application – Bart Apr 26 '15 at 15:25
  • why do you pass username and password as empty strings instead of just using the method with no username and password? – jtahlborn Apr 26 '15 at 15:40
  • i didn't notice i put that there, removing it fixed it though thanks – Bart Apr 26 '15 at 15:51
  • Glad to hear. Strange, though, because I tested that before commenting and it works for me whether I include `,"",""` or not. – Gord Thompson Apr 26 '15 at 16:02

1 Answers1

0

The message ´invalid authorization specification - not found:´ is shown because you try to access the database with a user which he cannot find, in you case "".

So you have to either input valid credentials

con = DriverManager.getConnection( DB , "<user>", "<password>");

or use another method to create the connection:

con = DriverManager.getConnection( DB );
Marvin Emil Brach
  • 3,853
  • 1
  • 28
  • 61