java连接access出现Message:[Microsoft][ODBC Microsoft Access Driver]找不到文件 '(未知的)'。

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.SQLException;
public class access{
//网桥JDBC/ODBC驱动程序
private static String DBDRIVER="sun.jdbc.odbc.JdbcOdbcDriver";
//数据库URL
private static String DBURL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Documents and Settings\\sms.mdb";

public static void main(String[] args) {
Connection con = null;
Statement stmt = null;
String createString = "create table student"+"(ID INTEGER,NAME char(8),grade NUMBER,class char(10))";
try {
Class.forName(DBDRIVER);//加载驱动程序
//建立与数据库的连接
con=DriverManager.getConnection(DBURL);
}
catch (ClassNotFoundException e) {
System.out.println("ClassNotFoundException:" + e.getMessage());
System.exit(1);//终止应用程序
}
catch (SQLException ex) {
System.out.println("SQLException:" + ex.getMessage());
System.exit(1);//终止应用程序
}
try {
stmt=con.createStatement();//创建SQL语句对象
stmt.executeUpdate(createString);//执行SQL语句
System.out.println("在SMS数据库创建表student成功");
}
catch (SQLException ex){
System.out.println("SQLExcepion:" + ex.getMessage());
}
finally {
if (stmt != null) {
try {
stmt.close();//关闭语句
}
catch (SQLException e) {}
}
if (con != null) {
try {
con.close();//关闭与数据库的连接
}
catch (SQLException e) {}
}
}//try/catch/finally块结束
}//main方法结束

}

运行结果总是显示SQLException:[Microsoft][ODBC Microsoft Access Driver] 找不到文件 '(未知的)'。已经建立了access数据源,有office软件,求高手指点一下呀

1,java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] '(未知的)'不是一个有效的路径。
2.确定路径名称拼写是否正确,以及是否连接到文件存放的服务器。 at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.ClothInputForm$1.actionPerformed(ClothInputForm.java:40)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6134)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
at java.awt.Component.processEvent(Component.java:5899)
at java.awt.Container.processEvent(Container.java:2023)
at java.awt.Component.dispatchEventImpl(Component.java:4501)
at java.awt.Container.dispatchEventImpl(Container.java:2081)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3965)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3895)
at java.awt.Container.dispatchEventImpl(Container.java:2067)
at java.awt.Window.dispatchEventImpl(Window.java:2458)
at java.awt.Component.dispatchEvent(Component.java:4331)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-06-24
你不是配置了数据源吗,
private static String DBURL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Documents and Settings\\sms.mdb";
没有必要这么写,可以改成
private static String DBURL = "jdbc:odbc:name1"; //这里name1是指你建的数据源名本回答被网友采纳
第2个回答  2015-08-05
提示数据库驱动找不到
导入“java。sql”jar包后要先加载驱动
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
第3个回答  2012-06-24
你这个路径不对,检查你的数据库的路径。
第4个回答  2012-06-24
文件不存在
相似回答