直接连数据库的时候一定要注意Microsoft Access Driver (*.mdb)中Driver后面的空格,我今天调试的半天才发现这个问题,郁闷至死~~~~~~~~~~
import java.sql.*;
public class DBConnection
{
public static void main(String args[])
{
try{
//String strurl="jdbc:odbc:driver={Microsoft Access Driver(*.mdb)};DBQ=db.mdb";
String strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=db.mdb";
//String strurl ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=db.mdb";//此为NO-DSN方式
//String strurl="jdbc:odbc:test";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("before connection");
Connection conn=DriverManager.getConnection(strurl);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from test");
if(rs.next())
{
System.out.println(rs.getString("id"));
}
}catch(Exception e)
{
System.out.println(e);
}
}
}
来源:https://www.cnblogs.com/amboyna/archive/2008/01/05/1026754.html