import java.sql.*;
import java.sql.SQLException;public class dbOperate {
//非数据源方式(即非桥接方式),连接Access数据库字符串,Database3.mdb为要连接的数据库
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=E:\\Database3.mdb";
Statement stmt = null;
Connection conn = null;
ResultSet rs = null;
public dbOperate() throws Exception{
//加载驱动
try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//连接Access数据库
conn=java.sql.DriverManager.getConnection(url);
}catch(SQLException e){
System.out.println(e.toString());
}
}
public void dbClose() throws SQLException {
if(rs != null){
try{
rs.close();
}catch(SQLException e){
e.printStackTrace();
}
}
if(stmt !=null ){
try{
stmt.close();
}catch(SQLException e){
e.printStackTrace();
}
}
if(conn !=null ){
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}
public ResultSet db_SQLQuery(String str)throws SQLException {
try{
//stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
stmt = conn.createStatement();
//查询数据库中的表
rs=stmt.executeQuery(str);
}catch(Exception e){
e.printStackTrace();
dbClose();
}
return rs;
}
} 错误提示:java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序调试结果,在 执行conn=java.sql.DriverManager.getConnection(url); 时出错。
新人求指教。
odbc数据源设了么
有这个不用设数据源了吧