Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- JButton btnNewButton = new JButton("Login");
- btnNewButton.setBackground(SystemColor.textHighlight);
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try {
- PreparedStatement pstmt;
- String query ="select student_id from students where username=? and password=?";
- pstmt = connection.prepareStatement(query);
- pstmt.setString(1, textField.getText());
- pstmt.setString(2, textField_1.getText());
- ResultSet rs = pstmt.executeQuery();
- if(rs.next())
- {
- JOptionPane.showMessageDialog(null,"Login success");
- st_id = rs.getInt("student_id"); /* I want to use this
- value in another form or class ? */
- }
- else if(textField.getText().equals("") && textField_1.getText().equals(""))
- {
- JOptionPane.showMessageDialog(null, "Field Empty");
- }
- else
- {
- JOptionPane.showMessageDialog(null, "Username or Password Invalid");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- });
Add Comment
Please, Sign In to add comment