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数据库连接错误解决办法的详细内容。