Home > Database > Mysql Tutorial > JDBC 与 Access 数据库连接报未发现数据源名称并且未指定默认驱

JDBC 与 Access 数据库连接报未发现数据源名称并且未指定默认驱

WBOY
Release: 2016-06-07 15:32:02
Original
1191 people have browsed it

代码如下: Class.forName(sun.jdbc.odbc.JdbcOdbcDriver); String strurl=jdbc:odbc:driver={Microsoft Access Driver(*.mdb)};DBQ=E://db.mdb; Connection conn=DriverManager.getConnection(strurl); Statement stmt=conn.createStatement(); ResultSet r

代码如下:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String strurl="jdbc:odbc:driver={Microsoft Access Driver(*.mdb)};DBQ=E://db.mdb";
Connection conn=DriverManager.getConnection(strurl);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from user");
while(rs.next())
{
    out.println(rs.getString("user-name"));
}

结果报错:java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 未发现数据名称并且指定默认驱动程序

 

原因:Driver 与 (*.mdb) 之间应该要有空格字符,而且只能是一个空字符,即

String strurl="jdbc:odbc:driver={Microsoft Access Driver(*.mdb)};DBQ=E://db.mdb"; 应为

String strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=E://db.mdb";

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template