Home>

Currently, the DB I am using wants to connect to the DB file from eclipse with "Access".

As an overview

Connect to "Database3.accdb" that you meet in the DB file from the DBAccess.java class
When the connection is established, "Connection successful" is displayed on the console.

For the time being, I think that's all for now.

Also, it is necessary to install the JDBC driver, but the installation is complete. (Already set)

What I went to myself
1: I get an error, so I tried using the Try Catch statement
2: Considering the path to connect to the database file and the JDBC driver not being installed normally, uninstall or reconfirm the path and describe it.
3: Download ucanaccess (I don't know the storage location, but can I already use it without installing it?)

The code and DB file name etc. are listed below, so please let us know.

DB file name: Database3.accdb

package Form1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
class DBAccess {
  public static void main (String [] string) {
try {
    Class.forName ("sun.jdbc.odbc.jdbcDriver");
} catch (ClassNotFoundException e) {
    // TODO auto-generated catch block
    e.printStackTrace ();
}
Connection con;
con = null;
try {
    con = DriverManager.getConnection ("jdbc: odbc: Database3.accdb");
} catch (SQLException e) {
    // TODO auto-generated catch block
    e.printStackTrace ();
}
try {
    Statement stmt = con.createStatement ();
} catch (SQLException e) {
    // TODO auto-generated catch block
    e.printStackTrace ();
}

  }
}


  • Answer # 1

    This is the same as the previous question.