Java connection to access database those pits

Source: Internet
Author: User

Java connects to an Access database using JDBC

Skills that need to be mastered

1.Java SE Basic Technology

2. Understand the point JDBC technology

Learn how to use Java to connect JDBC correctly

Environment

window8.1 64-bit

Jdk6 32-bit

Access 2013

Eclipse 4.4

Here is the code

Package Com.malin.app;import Java.sql.connection;import Java.sql.drivermanager;import java.sql.ResultSet;import java.sql.statement;/** * Java Connection Access * @author Marin * */public class Accesstest {public static void main (string[] args) t Hrows Exception {class.forname ("sun.jdbc.odbc.JdbcOdbcDriver"); String constr = "Jdbc:odbc:driver={microsoft Access Driver (*.mdb, *.accdb)};D bq=" + "e:\\accesstest.accdb"; Connection conn = drivermanager.getconnection (CONSTR); Statement stm = Conn.createstatement (); ResultSet rs = stm.executequery ("SELECT * from person"), while (Rs.next ()) {  System.out.println (rs.getstring (2));}}}

In fact, the connection code is similar, there is a connection method using ODBC.

Special need to pay attention to the big pit (really pit a day)

Need to be aware that your JDK Access version must be consistent (that is, access 32-bit JDK must be 32, or the error message will take you to the Detour), many of the online tutorials are copy to copy to not elaborate on this point, the first time with the easy accidentally drop the pit.

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.