• 0

[Java] MS access driver for mac/linux?


Question

Hi guys just a quick question, I've recently purchased a MacBook and installed the netbeans and opened a existing project that had developed using MS Access database(this can't be changed due to coursework).

No matter what i've tried I am unable to connect to the .mdb , I was wondering if it is possible at all to connect to the the database on a mac or linux?

Thanks

Matt

Link to comment
https://www.neowin.net/forum/topic/887410-java-ms-access-driver-for-maclinux/
Share on other sites

7 answers to this question

Recommended Posts

  • 0

You should be able to use ODBC using the JDBC bridge driver:

static {
	try {
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	} catch (ClassNotFoundException ex) {
		System.err.println("JDBC Bridget Driver not found.");
	}
}

public static Connection getConnection(string fileName) {
	string connection = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + fileName + ";DriverID=22;ReadOnly=false;";
	return DriverManager.getConnection(connection, "", "");
}

  • 0

I've tried this and a I get the following error

java.sql.SQLException: No suitable driver found for jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=/Users/Matt/Documents/CSSD/Application/database.mdb;DriverID=22;READONLY = FALSE}

  • 0
  On 30/03/2010 at 11:09, dontocsata said:

Do you have the jar with that Driver on the Classpath? It looks like you forgot to copy to jar over perhaps? Java is platform independent, so nothing (in general) special needs to be done when you switch to Linux or Mac.

Sorry how do I get the jar? I'm pretty new to java development, so simple lumens terms would be brilliant :D

  • 0

Alright, in Java to access a Database you need a 'Driver.' Drivers are specific to the type of database you're connecting to (mysql, postgresql, ms access). They are usually in a jar file and you put them in your lib folder. The original project probably had the driver you needed. Also make sure you're using the same SDK version.

Then you do what Antaris said:

static {
        try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                Class forName("driver.class.name"); //this is the class of the Driver, the Driver maker will have information for which class to use
        } catch (ClassNotFoundException ex) {
                System.err.println("JDBC Bridget Driver not found.");
        }
}

public static Connection getConnection(string fileName) {
        string connection = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + fileName + ";DriverID=22;ReadOnly=false;";
        return DriverManager.getConnection(connection, "", "");
}

Here is a list of Drivers for MS Access: http://developers.sun.com/product/jdbc/drivers/search_results.jsp?jdbc_version=0&vendor_name=&cert_mode=and&jdbc_driver_type_mode=and&dbms=6&dbms_mode=and&features_mode=and&results_per_page=50&submit=Search

Here is instructions about these Drivers: http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/bridge.doc.html

It would also be useful if you posted some code you're using. The code to connect to the database would be helpful.

  • 0

Ok this is the code

 public ResultSet insertDataConnection(String sql) throws Exception, SQLException{
        //String fileName = "C:\\Database\\database.mdb";
        String fileName = "/Users/Matt/Documents/CSSD/Application/database.mdb";
        String dbString = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + fileName + ";DriverID=22;READONLY = FALSE}";
        ResultSet results = null;
        System.out.println(DriverManager.getConnection(dbString,"",""));

        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            connection = DriverManager.getConnection(dbString);
            statement = connection.createStatement();
            results = statement.executeQuery(sql);
            return results;
        }
        catch(Exception e){
            //System.out.println(e);
        }
        return null;
    }

    private static Connection getConnection() throws Exception {
        String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
        String url = "jdbc:odbc:database.mdb";
        String username = "";
        String password = "";
        Class.forName(driver);
        return DriverManager.getConnection(url, username, password);
    }

if it is any help also I'm using netbeans!

And for the MS access driver is there any that are free all the ones i can see are paid/trails.

  • 0

I looked around a bit and found this: http://forums.sun.com/thread.jspa?threadID=5380580

You'll need to find a OBJC Driver for Mac/Linux. But it seems that its hard to come by/figure out. I'm sorry I can't help much beyond that. Might just need to Boot Camp or virtualize Windows for your course.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I would suggest Ubiquiti Cloud Gateway Fiber + U7 Pro XGS   https://store.ui.com/us/en/category/all-cloud-gateways/collections/cloud-gateway-fiber/products/ucg-fiber https://store.ui.com/us/en/category/wifi-flagship/products/u7-pro-xgs?variant=u7-pro-xgs-us I have been using this combo for 3 months now.
    • YouTube app is no longer compatible with several iPhones by Taras Buria Google is rolling out a new update for the YouTube app on iOS, and it is bad news for those still using an old iPhone. Starting with version 20.22.1, the latest release in the App Store, YouTube for iPhone now requires iOS 16 and newer. Previously, the app required a device with iOS 15 and newer. The new hardware requirement makes several iPhones incompatible with the latest version of the YouTube app. Those include the iPhone 6S / 6S Plus, iPhone 7 / 7 Plus, and the original iPhone SE. The seventh-generation iPod touch is also no longer compatible. On the iPad side, the update kicks out the second-generation iPad Air and the fourth-generation iPad mini. Although old iPhones can no longer install YouTube version 20.22.1 and newer, old versions continue working just fine. However, going forward, users will not receive new features and improvements. Also, at some point in the future, the app will stop working altogether. Another workaround is to use the web version of the app, but that also provides a limited experience compared to the up-to-date client. Google is not the only service that kicks out old and now unsupported Apple devices. Recently, WhatsApp developers dropped iPhones that cannot run iOS 15.1 or newer. The news is clearly a bummer for those who are still using their old iPhones, which, to Apple's credit, have a solid lifespan (as long as you are happy with the battery life). However, it is also worth keeping in mind that the iPhone 6S series was released almost a decade ago. Having ten years of support is impressive, but it is clearly time to move on. Perhaps my friend with his day-one iPhone 7 Black can finally consider buying something less ancient.
    • Guys have already appeared saying that Windows 11 ruined their lives, stole their bank password, killed their dog, kidnapped their mother and that's why they will never install Windows 11 again.
    • I think they start to use AI in Robots but in very early stage. I think in less than 20 years we will see these movies in real life
  • Recent Achievements

    • Reacting Well
      Cryptecks earned a badge
      Reacting Well
    • Week One Done
      primussolicitors798 earned a badge
      Week One Done
    • First Post
      nothin earned a badge
      First Post
    • Enthusiast
      Epaminombas went up a rank
      Enthusiast
    • Posting Machine
      Fiza Ali earned a badge
      Posting Machine
  • Popular Contributors

    1. 1
      +primortal
      188
    2. 2
      snowy owl
      134
    3. 3
      ATLien_0
      130
    4. 4
      Xenon
      119
    5. 5
      +FloatingFatMan
      97
  • Tell a friend

    Love Neowin? Tell a friend!