package com.access.Test;
import java.util.Properties;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class AccessTest {
public static void main(String[] args) throws SQLException {
AccessTest test = new AccessTest();
test.conn();
}
public void conn() throws SQLException {
Properties prop = new Properties();
prop.put("charSet", "gb2312"); // 这里是解决中文乱码
prop.put("user", "admin");
prop.put("password", "*#06#k");
String path = this.getClass().getClassLoader().getResource("data.mdb")
.getPath().substring(1);
String driverName = "net.sourceforge.jtds.jdbc.Driver";
String dbURL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="
+ path;
Connection dbconn = null;
try {
Class.forName(driverName);
dbconn = DriverManager.getConnection(dbURL, prop);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if (dbconn == null) {
return;
}
Statement stmt = dbconn.createStatement();
StringBuffer sb = new StringBuffer();
sb.append("select * from tuser");
ResultSet rs = stmt.executeQuery(sb.toString());
while (rs.next()) {
String name = rs.getString("UserName");
System.out.println(name);
}
}
}
最近下载更多
段朝洪 LV15
2023年12月3日
微信网友_6448337730736128 LV1
2023年4月25日
viivilife LV1
2021年2月2日
newhaijun LV16
2020年12月11日
小帅时代 LV7
2020年12月2日
wangdongtai LV31
2020年7月4日
victor8852 LV2
2020年3月22日
咔咔咔咔咔喇 LV1
2019年11月27日
xmjying LV13
2019年11月6日
oldtrybest LV8
2019年8月3日

最近浏览