Here is the error I am getting:
Expand|Select|Wrap|Line Numbers
- SQLException: No suitable driver found for jdbc:ucanacess:Database11
Here is my path for my MS Access Database that I am trying to connect:
Expand|Select|Wrap|Line Numbers
- 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.
Expand|Select|Wrap|Line Numbers
- 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());
- }
- }
- }