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.