How to connect to MS Acess Database with Java 8?
Here is the error I am getting:
Here is my path for my MS Access Database that I am trying to connect:
Take A look at the attached image. It will show you what jar files I have added to my project.
and here is the code I am using to connect to database.
Here is the error I am getting:
Code:
SQLException: No suitable driver found for jdbc:ucanacess:Database11
Here is my path for my MS Access Database that I am trying to connect:
Code:
C:\Users\dave\My_WorkSpace\Eclipse_Workspaces\workspace-jsp\Database11.accdb
Take A look at the attached image. It will show you what jar files I have added to my project.
and here is the code I am using to connect to database.
Code:
public class ex01 {
public static void main(String[] args) {
String url = "jdbc:ucanacess:Database11";
Connection con;
Statement stmt;
String query = "Select * from user";
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con = DriverManager.getConnection(url, "", "");
stmt = con.createStatement();
// Returns a ResultSet that contains the data produced by the query; never null
ResultSet rs = stmt.executeQuery(query);
System.out.println("User Data:");
System.out.println("FirstName\tLastName\tAge");
while (rs.next())
{
String fName = rs.getString("FirstName");
String lName = rs.getString("LastName");
int age = rs.getInt("age");
System.out.println(fName + "\t" + lName + "\t" + age);
}
stmt.close();
con.close();
}
catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
}
}
}
Comment