I've been unable to connect my Java program to my MS Access Database. The database file is in my Netbeans project folder under the name PhonesDatabase.accdb . This is the error I am receiving:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
Any feedback would be appreciated. The following is my current code:
import java.sql.*;
public class DB {
private static Connection conn = null;
public DB() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + System.getProperty("user.dir") + "\\PhonesDatabase.accdb");
} catch (Exception ex) {
System.out.println("Error");
}
}
ResultSet queryTbl (String sqlStmt) throws SQLException
{
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sqlStmt);
return rs;
}//end queryTbl
void updateTbl (String update) throws SQLException
{
Statement stmt = conn.createStatement();
stmt.executeUpdate(update);
stmt.close();
}//end updateTbl
}//end DB class
Thanks NF