Guest User

Untitled

a guest
Jun 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.*;
  3. import java.util.*;
  4.  
  5. public class TestaConexao {
  6. public TestaConexao() {
  7. Connection conn = new Conexao().conectar();
  8. try {
  9. Statement select = conn.createStatement();
  10. ResultSet result = select.executeQuery("select login, senha from usuarios");
  11. while (result.next()) {
  12. String login = result.getString("login");
  13. String password = result.getString("senha");
  14. Scanner sc = new Scanner (System.in);
  15. System.out.println("Login: ");
  16. String nick = sc.nextLine();
  17. System.out.println("Senha: ");
  18. String senha = sc.nextLine();
  19. if (login.equals(nick) && password.equals(senha)) {
  20. System.out.println("Você está logado");
  21. } else {
  22. System.out.println("Login e/ou senha invalidos.");
  23. }
  24. }
  25. } catch (Exception ex) {
  26. System.out.println("Ocorreu um erro ao selecionar tabela.");
  27. }
  28. }
  29. }
Add Comment
Please, Sign In to add comment