Guest User

Untitled

a guest
Mar 29th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. JButton btnNewButton = new JButton("Login");
  2. btnNewButton.setBackground(SystemColor.textHighlight);
  3. btnNewButton.addActionListener(new ActionListener() {
  4. public void actionPerformed(ActionEvent arg0) {
  5. try {
  6. PreparedStatement pstmt;
  7. String query ="select student_id from students where username=? and password=?";
  8. pstmt = connection.prepareStatement(query);
  9. pstmt.setString(1, textField.getText());
  10. pstmt.setString(2, textField_1.getText());
  11. ResultSet rs = pstmt.executeQuery();
  12. if(rs.next())
  13. {
  14. JOptionPane.showMessageDialog(null,"Login success");
  15. st_id = rs.getInt("student_id"); /* I want to use this
  16. value in another form or class ? */
  17. }
  18. else if(textField.getText().equals("") && textField_1.getText().equals(""))
  19. {
  20. JOptionPane.showMessageDialog(null, "Field Empty");
  21. }
  22. else
  23. {
  24. JOptionPane.showMessageDialog(null, "Username or Password Invalid");
  25. }
  26. } catch (SQLException e) {
  27. e.printStackTrace();
  28. }
  29.  
  30. }
  31. });
Add Comment
Please, Sign In to add comment