我有一个登录用户界面。当登录时执行用户 ID 和登录 ID 插入到日志记录表中。UI 有用户名字段、密码字段和分支字段。当名称、密码、分支被填写并按下登录按钮时,用户 ID 和日志日期插入到日志表中。我怎么能解决这个问题。
在记录表中插入表............
public User insertuserloginDate(Connection con,int userid,Timestamp logtime){
String sql="INSERT into logging values(?,?,?)";
String sql1="Select * from user";
try {
Statement stm=con.createStatement();
// ResultSet rs=stm.executeQuery(sql1);
// while (rs.next()){
User u=new User(rs.getInt(1));
// return u;
}
PreparedStatement ps=con.prepareStatement(sql);
ps.setInt(1, userid);
ps.setTimestamp(2, logtime);
ps.setInt(3, getRecord());
ps.executeUpdate();
ps.close();
con.close();
} catch (SQLException ex) {
System.out.println("Error while login record " + ex);
}
return null;
并在按钮动作中............
private void buttonloginActionPerformed(java.awt.event.ActionEvent evt) {
char[] temp_pwd = userpassword.getPassword();
String pwd = null;
pwd = String.copyValueOf(temp_pwd);
System.out.println("password " + pwd);
//try {
// TODO add your handling code here:
if (user.loginApplication(connect.getCon(), username.getText(),
pwd, userbranch.getSelectedItem().toString())) {
System.out.println("success ");
MainForm mainForm = new MainForm();
mainForm.setVisible(true);
user.insertuserloginDate(connect.getCon(), user.getUid(), user.getLogdate());
System.out.println("record user log time " +user.getUid());
// user.getuser(connect.getCon());
}else {
JOptionPane.showMessageDialog(null, "Login Failed!", "Failed!",
JOptionPane.ERROR_MESSAGE);
}
}