There are two ways to connect to an Access database in Java
- 2020-04-01 03:56:14
- OfStack
There are two ways to connect to MS Access in Java:
1. The JDBC, ODBC
Java connection Access can use MS management tools - - gt; The data source (ODBC) Settings establish the connection so that you do not need to import the jar. This, however, requires that every machine on which the program is deployed be set up. So I'm not going to use it now.
2. JDBC
Java can also connect to MS Access just like any other database, import the corresponding jar package of the database, and make the connection.
java Access JDBC jar Package: Access_JDBC30.jar
Refer to the following code for specific connection:
try {
/// load driver jar
Class.forName("com.hxtt.sql.access.AccessDriver").newInstance();
//Specifies the location of the Access database file
String url = "jdbc:Access:///c:/a/db.mdb";
//Establish a connection
conn = DriverManager.getConnection(url, "username", "password");
} catch (Exception e) {
e.printStackTrace();
}
Other queries and other database, such as: / / www.jb51.net/article/68620.htm
3. Specification:
Now basic will not use ODBC way to connect to the database, also do not use Access, like I took out the old program before today want to run a run to see is Access, or use JDBC.