Menu

error creating a new database file "given file does not exist:"

Help
Artur
2014-09-02
2014-09-02
  • Artur

    Artur - 2014-09-02

    Hey everybody,

    i have a problem creating a new database file with ucanaccess.

    Here is my code:

    if (db.equals("ms-access")) {
    Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
    cn = DriverManager.getConnection("jdbc:ucanaccess://"
    + database.getAbsolutePath());
    }

    'database' is a File Object an not yet existing. So the DriverManager should create the file. But instead i get the error:

    net.ucanaccess.jdbc.UcanaccessSQLException: given file does not exist: C:\folder\example.mdb
    at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:204)
    at java.sql.DriverManager.getConnection(DriverManager.java:579)
    at java.sql.DriverManager.getConnection(DriverManager.java:243)

    The almost same code works fine with sqllite database and the file is created automatically if its not existing.

    Anybody got an idea why this happens?

    Thank you.

     
  • Marco Amadei

    Marco Amadei - 2014-09-02

    Hi Artur,
    That the "DriverManager should create the file" isn't correct.
    It's the driver that could do that, but you have to specify the format version:
    through the Newdatabaseversion parameter.
    Valid values are V2000, V2003, V2007, V2010.
    e.g.

    DriverManager.getConnection("jdbc:ucanaccess://"
    + database.getAbsolutePath()+";newdatabaseversion=V2010");

     

Log in to post a comment.