Results 1 to 3 of 3
  1. #1
    rockspud5693 is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Unhappy Connect to Access 2010 DB file (.accdb)

    I know there are like a million forum threads about this topic, but so far none of the solutions that I've found have worked! I can connect to an Access DB so easily in VB, but in Java it's a whole lot more difficult :(

    Software I'm using
    -Windows 7 (64bit)
    -Access 2010 (32bit)
    - Netbeans 7.0.1 (32bit?)

    What I need to do:
    -Read/Update/Write/Delete/Perform queries on an Access file (.accdb).
    -The project created then needs to be able to run on any computer, without access to a server.
    -The user should not have to edit computer settings such as ODBC DSN's to run the project.

    Code I've tried:
    import java.sql.*;

    public class TestA {

    public static void main(String[] args)
    {
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    // set this to a MS Access DB you have on your machine
    String filename = "C:\\RPA\\RASP.accdb";
    String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.accdb)};DBQ=";
    database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
    // now we can get the connection from the DriverManager
    Connection con = DriverManager.getConnection( database ,"","");
    }
    catch (Exception e) {
    System.out.println("Error: " + e);
    }
    }
    }
    Error: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

    I also tried to connect to a Derby database from Netbeans as an alternative but that didn't work either:
    import java.sql.*;

    public class Derb {

    public static void main(String[] args)
    {
    try {
    Class.forName("org.apache.derby.jdbc.EmbeddedDrive r");
    // set this to a MS Access DB you have on your machine
    //String filename = "C:\\RPA\\MyDbTest";
    String database = "jdbc:derby:MyDbTest";
    //database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
    // now we can get the connection from the DriverManager
    Connection con = DriverManager.getConnection( database ,"","");
    }
    catch (Exception e) {
    System.out.println("Error: " + e);
    }
    }
    }
    Error: java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver


    I have tried every combination of "jdbc:odbc:...." and it still doesn't connect. I just need to add/remove/view data from the Access file, and the project needs to be able to access the file on any computer without internet connection AND without the user having to edit computer settings such as ODBC DSN's. I am not too bothered if I have to change to different software to do this, however I would prefer to implement it in Access. I know enough SQL, and SQL*Plus to implement it in an Oracle DB/other.

    Is there a (hopefully) super simple way of doing this?

  2. #2
    rockspud5693 is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: Connect to Access 2010 DB file (.accdb)

    I was thinking that perhaps I haven't got the correct libraries installed on netbeans.....?

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,856
    Rep Power
    19

    Default Re: Connect to Access 2010 DB file (.accdb)

    Quote Originally Posted by rockspud5693 View Post
    I know there are like a million forum threads about this topic, but so far none of the solutions that I've found have worked! I can connect to an Access DB so easily in VB, but in Java it's a whole lot more difficult :(
    I wish people wouldn't do this. VB was written by Microsoft, as was Access, so it's no great surprise that the two of them were built to talk to each other.

    Quote Originally Posted by rockspud5693 View Post
    Error: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    OK, have you set up an ODBC datasource for the database? That's what's needed here, which you'll find info on at Microsoft.
    If you want to blame someone blame MS for not providing a decent JDBC driver for Access and simply relying on the (frankly rubbish) bridge.

    Quote Originally Posted by rockspud5693 View Post
    I also tried to connect to a Derby database from Netbeans as an alternative but that didn't work either:

    Error: java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
    And this is because the Derby JDBC driver is not on your runtime class path.
    Have you gone through the JDBC tutorials over at Oracle?

    Quote Originally Posted by rockspud5693 View Post
    I have tried every combination of "jdbc:odbc:...." and it still doesn't connect. I just need to add/remove/view data from the Access file, and the project needs to be able to access the file on any computer without internet connection AND without the user having to edit computer settings such as ODBC DSN's. I am not too bothered if I have to change to different software to do this, however I would prefer to implement it in Access. I know enough SQL, and SQL*Plus to implement it in an Oracle DB/other.

    Is there a (hopefully) super simple way of doing this?
    Then don't use Access, because you'll need a data source set up.
    Access is rubbish for this when trying to tie it to Java.
    Use Derby or a similar embedded db.

Similar Threads

  1. Replies: 0
    Last Post: 08-09-2011, 08:47 AM
  2. connect java to MS Access Database
    By needjavahelp in forum New To Java
    Replies: 5
    Last Post: 07-14-2010, 01:53 PM
  3. how to connect java to MS Access database
    By Manfizy in forum New To Java
    Replies: 4
    Last Post: 12-24-2009, 04:50 PM
  4. Connect to Access without MS ODBC?
    By ribbs2521 in forum New To Java
    Replies: 5
    Last Post: 04-16-2009, 03:33 AM
  5. connect to microsoft access
    By bbq in forum JDBC
    Replies: 1
    Last Post: 07-09-2007, 03:33 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •