1

I have created a CRUD Application the connecting method of the application is given below. I have tested it on my computer and is working fine, but while tesing on another computer where MS Access is not installed it is throwing NullPointerException.

So what should I do in order to rectify this problem? Are there any libraries for connecting to .mdb files?

These should also run on Linux. I can convert the .mdb file into Open Office Base if Libraries are available...

void DoConnect()
{
    try{
    String current = new java.io.File( "." ).getCanonicalPath();
    current+="\\DataBases\\Quiz.mdb";
    String host = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+current+";";
    String uName = "";
    String uPass = "";
    con=new Connection[Size];
    stmt=new Statement[Size];
    for(int i=0;i<Size;i++)
    {
        con[i]=DriverManager.getConnection(host, uName, uPass);
        stmt[i]=con[i].createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
    }
    ts=stmt[0].executeQuery("SELECT * FROM Quiz");
    ts.first();
    rs=stmt[1].executeQuery("SELECT ANSW FROM Quiz");       

    System.out.print(rs.getString("STM1"));
    }catch (IOException | SQLException err) {

    }      
}
2
  • Which line is throwing the exception ? Commented Apr 19, 2013 at 8:55
  • con[i]=DriverManager.getConnection(host, uName, uPass); Commented Apr 19, 2013 at 9:40

2 Answers 2

1

Are there any libraries for connecting to mdb files ?

Yes, there are. The Jet database engine is included with Windows, but only a 32-bit version is available. If your application is running as a 64-bit process then you'll need to have the 64-bit version of the Access Database Engine (a.k.a. ACE) installed on the machine. You can download the Access Database Engine here:

http://www.microsoft.com/en-us/download/details.aspx?id=13255

Note that to use the Access Database Engine you may have to tweak your connection string to something like...

String host = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="+current+";";

...and if that doesn't work on 32-bit machines without the Access Database Engine installed (i.e., machines with just the Jet database engine) then your code may have to

  1. try the Jet connection string first (i.e., your original connection string), and if that fails then

  2. try the ACE connection string (i.e., the one in this answer).

Sign up to request clarification or add additional context in comments.

2 Comments

What About libraries for OpenOffice Base . I want the program to run on Linux Too
@SidharthVinod The last time I checked there was no ODBC driver for accessing data in Open Office Base databases. I believe that the underlying database architecture is (or was) HSQLDB, so you might find some more up-to-date information there.
0

Connecting to Access is not an easy task if you don't have access installed on all client computers . Moreover Access databases are huge in size . So I am currently using H2 database which is very easy to use . Regarding the size , After I copied a 140 Mb Access database to H2 the file was ONLY 732 Kb !

More info can be found here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.