【发布时间】:2015-02-12 06:18:44
【问题描述】:
String sql = "Select * from EmployeeAccount";
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/AttendanceSystemTest","root","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
String user=txtid.getText();
String pwd=new String (password.getPassword());
int loop=0;
while(rs.next()) {
String uname=rs.getString("Emp_ID");
String password=rs.getString("Password");
if ((user.equals(uname)) && (pwd.equals(password))) {
String s1 = "insert into Attendance (Emp_ID,Date,Time_in) Values ('" + user + "', now(), curtime());";
stmt.executeUpdate(s1);
loop++;
}
}
rs.close();
if (loop==0) {
JOptionPane.showMessageDialog(null, "Username and Password not in database!");
}
}
catch (Exception e) {
JOptionPane.showMessageDialog(null,e);
}
【问题讨论】:
-
格式化你的代码!目前您的问题很难阅读。