举一个例子
连接数据库查询表的相关语句(表userinfo中字段有username,password,下同):
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=E:/mydata.mdb","","");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from userinfo");
while(rs.next())
{
out.print("
用户名:"+rs.getString("username")+"密码:"+rs.getString("password"));
}
rs.close();
stmt.close();
conn.close();