import java.sql.*;
class test{
public static void main(String args[])
{
String sqlStr = "select * from haha where id=201";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("类实例化成功!" );
String url="jdbc:odbc:aa";
//改为 String url="jdbc:odbc:driver={Microsoft Access Driver(*.mdb)};DBQ=db2.mdb"; 就提示出错.....
Connection con = DriverManager.getConnection(url);
System.out.println("创建连接对像成功!" );
Statement st = con.createStatement();
System.out.println( "创建Statement成功!" );
ResultSet rs = st.executeQuery( sqlStr );
System.out.println( "操作数据表成功!" );
System.out.println( "----------------!" );
while (rs.next())
System.out.println(rs.getString(1) + " " + rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4));
rs.close();
st.close();
con.close();
}
catch(Exception err)
{
err.printStackTrace(System.out);
}
}
}