Two ways for Java to connect to an Access database _java

Source: Internet
Author: User
Tags odbc access database

Two ways for Java to connect to MS Access:

1.jdbc-odbc

Java connection Access can establish a connection using MS's own administrative tools--> data Source (ODBC) settings so that you do not need to import jars. However, there are no aspects to be set on each machine where the program is deployed. So it's not going to work now.

2.JDBC

Java can also connect to Ms Access as you connect to other databases, import the appropriate jar packages for your database, and connect.

Copy Code code as follows:

Java Access JDBC jar package: Access_jdbc30.jar

For specific connections, refer to the following code:
Copy Code code as follows:

try {
Load Drive jar
Class.forName ("Com.hxtt.sql.access.AccessDriver"). newinstance ();
Specify 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 are the same as other databases, such as: http://www.jb51.net/article/68620.htm

3. Description:

Now basically do not use the ODBC way to connect the database, also basically do not use access, like I took out the old program today want to run a run a look is access, or use JDBC Bar.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.