64位Windows系统连接Access数据库,程序中可能需要修改Access数据库连接:
32位:String strUrl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=c://demo.mdb"
64位:String strUrl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=c://demo.mdb"
修改后仍报错则进入“控制面板”-》“管理工具”-》“数据源(ODBC)”查看系统是否存在Access驱动
若不存在则需要安装Microsoft Access驱动程序:
官方:http://www.microsoft.com/zh-cn/download/confirmation.aspx?id=13255
32位:http://download.microsoft.com/download/E/4/2/E4220252-5FAE-4F0A-B1B9-0B48B5FBCCF9/
AccessDatabaseEngine.exe
64位:http://download.microsoft.com/download/E/4/2/E4220252-5FAE-4F0A-B1B9-0B48B5FBCCF9/
AccessDatabaseEngine_X64.exe
下面是连接access的.mdb文件,解析代码:
package test; import java.io.File; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; import java.util.Properties; public class Test { /** * TODO : 读取文件access * * @param filePath * @return * @throws ClassNotFoundException */ public static void readFileACCESS(File mdbFile) { Properties prop = new Properties(); prop.put("charSet", "gb2312"); // 这里是解决中文乱码 prop.put("user", ""); prop.put("password", ""); //String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=" + mdbFile. getAbsolutePath(); String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="+ mdbFile. getAbsolutePath(); Statement stmt = null; ResultSet rs = null; String tableName = null; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // 连接到mdb文件 Connection conn = DriverManager.getConnection(url, prop); ResultSet tables = conn.getMetaData().getTables( mdbFile.getAbsolutePath(), null, null, new String[] { "TABLE" }); // 获取第一个表名 if (tables.next()) { tableName = tables.getString(3);// getXXX can only be used once } else { return; } stmt = (Statement) conn.createStatement(); // 读取第一个表的内容 rs = stmt.executeQuery("select * from " + tableName); ResultSetMetaData data = rs.getMetaData(); while (rs.next()) { for (int i = 1; i <= data.getColumnCount(); i++) { System.out.print(rs.getString(i) + " "); } System.out.println(); } } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { readFileACCESS(new File("C:\\Users\\Ninemax\\Desktop\\西太区医学索引.mdb")); } }
python学习网,大量的免费access数据库教程,欢迎在线学习!
위 내용은 Access 데이터베이스 연결 오류 해결 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!