Question

Here is my issue. I'm working on an App for a client so that they can update data into an MS Access database that is located on a web server. The server is set up for ODBC and I do have a DSN set up. I think I'm missing something in the syntax when it comes to actually connecting to the database. With the current code set up I'm getting a "No suitable Driver" exception thrown back.

I replaced the obvious un/pw with "user" and "pass". I also replaced the url with the web server's url address and the database file name with myDB.mdb

Here is my code:

//gets the connection driver
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    } catch (ClassNotFoundException e) {
        System.err.println("Driver name is incorrect or unable to be found.");
        e.printStackTrace();
    }
    try {
        Connection connect = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:url/db/myDB.mdb;","user","pass");
        connect.close();
    } catch (java.sql.SQLException ex) {
        // handle any errors
        error.setText(String.valueOf("SQLException: " + ex.getMessage()));
    }

I'm new to connecting to a database in Java so I'm sure I'm missing something simple, but I would appreciate any help I can get.

I've been researching this online for a few hours and have gotten no where.

Was it helpful?

Solution

You shouldn't connect directly from your phone to a database that's sitting on a server somewhere.

A better solution would be to set up a web service on the server that allows you to read/update the database, and then call that web service from the Android app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top