private boolean checkLoginFromAccess(String id,String pswd){
PreparedStatement stmt = null;
ResultSet rest = null;
Connection conn = null;
String path = this.getServletContext().getRealPath("")+"/WEB-INF/lib/hr.mdb";
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+path;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");// 用JDBC-ODBC方式
conn = DriverManager.getConnection(url);
String sql = "select * from user where account = ? and password = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, id);
stmt.setString(2, pswd);
rest = stmt.executeQuery();
if(rest.next()){
return true;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
if(stmt != null){
stmt.close();
}
if(conn != null){
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return false;
}