Advertisement
Guest User

Untitled

a guest
Mar 16th, 2016
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. package nkotb;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.util.Scanner;
  9.  
  10. public class Login {
  11.  
  12.  
  13. Scanner userInput = new Scanner(System.in);
  14. PreparedStatement stmt = null;
  15. ResultSet rs = null;
  16. Connection conn = null;
  17.  
  18. public void Login() {
  19.  
  20. System.out.println("Name:");
  21. String loginUsername = userInput.next();
  22. System.out.println("Password:");
  23. String loginPassword = userInput.next();
  24.  
  25. try {
  26. Connect conObj = new Connect();
  27. conObj.Connection();
  28. //2. Skapa ett statement med scannervaribaler.
  29. stmt = conn.prepareStatement("SELECT * FROM customers WHERE Name ='" + loginUsername + "' AND Password='" + loginPassword + "' ; ");
  30. //3. Kör sql-query
  31. rs = stmt.executeQuery();
  32.  
  33. while (rs.next()) {
  34. String dbName = rs.getString("Name");
  35. String dbSurname = rs.getString("Surname");
  36.  
  37. System.out.println("Welcome " + dbName + " " + dbSurname + "");
  38. }
  39.  
  40. } catch (SQLException exc) {
  41. System.out.println(exc.getMessage());
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement