This is my code:
public class ConnectDB {
Connection conn;
Scanner kb=new Scanner(System.in);
public String ID;
public ConnectDB()
{
try
{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println ("Driver successfully loaded");
}
catch (ClassNotFoundException c)
{
System.out.println ("Unable to load database driver");
}
//connect to the database
try
{
String filename = "PATPhase2DB.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb,*.accdb)};DBQ=";
database += filename.trim () + ";DriverID=22;READONLY=true}";
conn = DriverManager.getConnection (database,"","");
System.out.println ("Connection to database successfully established");
}
catch (Exception e)
{
System.out.println ("Unable to connect to the database");
}
}
The Messages Are:
Driver successfully loaded
Unable to connect to the database
java.lang.NullPointerException
This has worked on a different computer than mine, connecting to the database through exactly the same code. I am also running Windows 8.