title: Access (.mdb) Database manipulation with jdbc
body: <p>Background: Working on an application to be run on an Apache server hosted by Network Solutions.  Friend/Customer insisted on using an Access Database instead of SQL database.</p>
  
  <p>Current Problem:  Wrote a Java test program to make sure I can connect to the database before I dive head first into writing the whole backend.  When I run this code on the JVM of the apache server the final product will be hosted:</p>
  
  <pre><code>import java.sql.*;
  import java.io.*;
  public class test {
      public static void main(String[] args) {
          try {
              Class driverClass = Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              DriverManager.registerDriver((Driver) driverClass.newInstance());
  
              // set this to a MS Access DB you have on your machine
              String filename = new File(".").getCanonicalPath() + "/ITEMS.mdb";
  
  
              String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
              database+= filename.trim(); // add on to the end 
              // now we can get the connection from the DriverManager
  
              System.out.println(database);
  
              Connection conn = DriverManager.getConnection( database );
          } catch (Exception e) {
              System.out.println("Error: " + e.getMessage() + " " + e.getLocalizedMessage());
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>I get a null pointer exception on the line Connection conn= DriverManager.getConnection( database)</p>
  
  <p>Here is the stacktrace:</p>
  
  <pre><code>java.lang.NullPointerException
  
          at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:436)
  
          at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153)
  
          at java.sql.DriverManager.getConnection(DriverManager.java:582)
  
          at java.sql.DriverManager.getConnection(DriverManager.java:207)
  
          at test.main(test.java:20)
  </code></pre>
  
  <p>To write this test I used this as my primary source: <a href="http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2691&amp;lngWId=2" rel="nofollow">http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2691&amp;lngWId=2</a></p>