I checked everywhere i could and including this page but i keep getting weird error on Netbeans 8 and Ucanaccess.
Here is what i did first. Imported org-apache-commons-logging.jar, ucanaccess-2.0.9.jar, commons-lang-2.6.jar, hsqldb.jar, jackcess-2.0.4.jar as a new driver.
Set the class path under options in Netbeans (added the ucanaccess.zip file)
import sun.jdbc.odbc.JdbcOdbcDriver;
import net.ucanaccess.jdbc.UcanaccessDriver;
import java.sql.*;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
public class JavaApplication7 {
static final String JDBC_DRIVER = "net.ucanaccess.jdbc.UcanaccessDriver";
static final String DB_URL = "jdbc:ucanaccess://C:\\Users\\Magneto\\Documents\\Database1.mdb";
static final String USER = "";
static final String PASS = "";
static final Scanner in = new Scanner(System.in);
//insert data variables
public JavaApplication7() throws SQLException {
}
public static void main(String[] args){
// databaseForm dbf = new databaseForm();
// dbf.setVisible(true);
getDatabase();
}
public static void connectToDatabase()
{
try{
System.out.println("Connection Successfull");
System.out.println("----------------------------------------------");
}
catch(Exception e)
{
}
}
public static void getDatabase()
{
try {
Class.forName(JDBC_DRIVER);
Statement statement = null;
Connection con = DriverManager.getConnection(DB_URL, "", "");
//execute a query
statement = con.createStatement();
String sql = "Select id, FirstName, LastName FROM PhoneBook";
ResultSet rs = statement.executeQuery(sql);
//pull database
while(rs.next())
{
int id = rs.getInt("id");
String FirstName = rs.getString("FirstName");
String LastName = rs.getString("LastName");
System.out.println("id " + id + " FirstName " + FirstName + " LastName " + LastName);
}
rs.close();
con.close();
} catch (Exception ex) {
System.out.println("Got an Exception!");
System.err.println(ex.getMessage());
}
}
And here is the error I keep getting:
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:188)
at javaapplication7.JavaApplication7.getDatabase(JavaApplication7.java:54)
at javaapplication7.JavaApplication7.main(JavaApplication7.java:34)
Caused by: java.lang.RuntimeException: org.hsqldb.jdbc.JDBCDriver
at net.ucanaccess.jdbc.UcanaccessDriver.<clinit>(UcanaccessDriver.java:56)
... 4 more
Java Result: 1