Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. btnLogIn.addActionListener(new ActionListener() {
  2. @SuppressWarnings({ "deprecation" })
  3. public void actionPerformed(ActionEvent arg0) {
  4. // creating connection and query variables
  5. Connection conn = null;
  6. ResultSet rs = null;
  7. PreparedStatement pst = null;
  8. String url = "jdbc:mysql://MY.DB.URL/*******";
  9.  
  10. //load the driver
  11. try {
  12. Class.forName("com.mysql.jdbc.Driver");
  13.  
  14. // making connection
  15. conn = DriverManager.getConnection(url, "*******", "*******");
  16. // query
  17. String sql = "select * from log_in where username = ? and pssword = ?";
  18. pst = conn.prepareStatement(sql);
  19. pst.setString(1, UsernameField.getText());
  20. pst.setString(2, PasswordField.getText());
  21. rs = pst.executeQuery(sql);
  22.  
  23. if(rs.next()){
  24. //Retrieve by column name
  25. String username = rs.getString("username");
  26. System.out.println("Username : " + username);
  27. String password = rs.getString("pssword");
  28. System.out.println("Password : " + password);
  29. lblLog_In.setText("Welcome.");
  30. } else {
  31. lblLog_In.setText("ERROR: invalid log in information.");
  32. }
  33. } catch (SQLException e) {
  34. System.out.println("SQL Exception.");
  35. } catch (ClassNotFoundException e) {
  36. System.out.println("Class not found exception.");
  37. }
  38. }
  39. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement