日期:2014-05-17  浏览次数:20743 次

JAVA 连接 Access 数据库,提示文件名无效,急,在线等,马上结帖
package bluec.base;

import java.sql.Connection;
import java.sql.DriverManager;

public class CConnect {

public static Connection getConnection() {
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ = F:/ydtvip.mdb";
String user = "";
String pwd = "";
try {
Class.forName(driver);
return DriverManager.getConnection(url, user, pwd);
} catch (Exception e) {
System.err.println("异常:"+e.getMessage());
return null;
}
}
}


异常:[Microsoft][ODBC Microsoft Access Driver] 文件名无效。



------解决方案--------------------
F:/ydtvip.mdb --> F:\\ydtvip.mdb
试试
------解决方案--------------------

Java code
String url="jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/ydtvip.mdb");