我之前用的老版本的Eclipse和access连接数据库没有问题能够输出数据 现在用的最新的luna和2013的access 就会出现sun.jdbc.odbc.JdbcOdbcDriver,也没有数据返回代码如下
import java.sql.*;
public class AC {
Connection conn =null;
Statement stmt =null;
public AC(){}
public void creatConnectInstance(){
String strurl = "jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb, *.accdb)};DBQ=C:\\Users\\Admin\\Desktop\\q1.accdb";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection(strurl);
stmt=conn.createStatement();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public void destroyConnectInstance(){
try{
conn.close();
}
catch(Exception e){
System.out.println(e.getMessage());
}}
public void queryLinkMan(){
this.creatConnectInstance();
try{
ResultSet rs =stmt.executeQuery("select * from a");
System.out.println("connect with access");
while(rs.next()){
System.out.println(rs.getString(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3));
}}
catch(Exception e){
System.out.println(e.getMessage());}
this.destroyConnectInstance();
}
public static void main(String[] args){
new AC().queryLinkMan();
}
}
后来的结果如下
sun.jdbc.odbc.JdbcOdbcDriver
null
null