java 代码连接access数据库,并获取数据
作者:互联网
1.先导入需要的Maven坐标
<!-- java1.8 连接access数据库 -->
<dependency>
<groupId>net.sf.ucanaccess</groupId>
<artifactId>ucanaccess</artifactId>
<version>4.0.4</version>
</dependency>
2.编写连接并获取数据的代码
try {
//加载驱动
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
//access数据库存放的位置
String mdbPath = "E:\\ZKTeco\\att2000.mdb";
Connection conn = DriverManager.getConnection("jdbc:ucanaccess://" + mdbPath);
//获取连接对象 stmt
Statement stmt = conn.createStatement();
//要执行的sql语句
ResultSet rs = stmt.executeQuery("select * from tableName");
//解析从access数据库中查出的结果集sex
while (rs.next()) {
String sex = rs.getString("sex");
String name = rs.getString("Name");
System.out.println("姓名:"+name+"------性别为:"+sex );
}
rs.close();
stmt.close();
} catch (Exception e) {
e.printStackTrace();
}
标签:java,String,rs,stmt,sex,access,获取数据,ucanaccess 来源: https://blog.csdn.net/OOObject/article/details/121082634