public static ResultSet get(String filePath,String oldChannelName) {
Properties prop = new Properties();
prop.put("charSet", "gb2312"); // 这里是解决中文乱码
prop.put("user", "");
prop.put("password", "");
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="
+ filePath; // 文件地址
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(url, prop);
stmt = (Statement) conn.createStatement();
rs = stmt.executeQuery("select * from News where SmallClassName='"+oldChannelName+"'");
return rs;
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
64为access下载地址:
http://download.microsoft.com/download/E/4/2/E4220252-5FAE-4F0A-B1B9-0B48B5FBCCF9/AccessDatabaseEngine_X64.exe
下载安装完毕,配置数据源
原来是{Microsoft Access Driver (*.mdb)}
修改为{Microsoft Access Driver (*.mdb, *.accdb)}。
代码测试,可用。