import java.sql.*; public class CoalTotals { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { //加载数据库支持的驱动 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ =E://Dev//WorkSpace//chapter21//bin//WORLD20.MDB"; try { //建立数据源连接 Connection conn=DriverManager.getConnection(url,"",""); Statement st = conn.createStatement(); ResultSet rec = st.executeQuery("select * " + "from Coal"); System.out.println("FIPS/tCOUNTRY/tYEAR/t" + "ANTHRACITE PRODUCTION"); while(rec.next()) { System.out.println(rec.getString(1) + "/t" + rec.getString(2) + "/t" + rec.getString(3) + "/t" + rec.getString(4)); } st.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } 这里的url连接一定要注意 不要多个空格少个空格的都不行 因为我写的时候就多了个空格 就提示我 文件名错误 其他注意下连接数据库的步骤基本就没什么大问题了~~