Advertisement
Raizekas

Untitled

Mar 17th, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. package db.veiksmai;
  2.  
  3. import db.entities.Vartotojas;
  4.  
  5. import java.sql.*;
  6.  
  7. public class DuombazesVeiksmai
  8. {
  9. public static Connection sukurtiDuombaze() throws SQLException
  10. {
  11. String dbServeris = "jdbc:mysql://localhost:3306/";
  12. String dbPav = "gui_app_db";
  13. String dbLogin = "root";
  14. String dbPsw = "";
  15. return DriverManager.getConnection(dbServeris + dbPav, dbLogin, dbPsw);
  16. }
  17.  
  18.  
  19. public static void palygintiVartDuomenis(Connection jungtis, Vartotojas v1) throws SQLException
  20. {
  21. String sqlRastiVart = "SELECT * FROM vartotojai WHERE login=?";
  22.  
  23. PreparedStatement prepSt = jungtis.prepareStatement(sqlRastiVart);
  24.  
  25. prepSt.setString(1, v1.getLogin());
  26.  
  27. ResultSet gautiVartotojai = prepSt.executeQuery();
  28.  
  29. int kiekVartotoju = 0;
  30. Vartotojas v2 = new Vartotojas();
  31. while (gautiVartotojai.next())
  32. {
  33. v2.setLogin(gautiVartotojai.getString("login"));
  34. v2.setPsw(gautiVartotojai.getString("psw"));
  35. kiekVartotoju++;
  36. }
  37.  
  38. if (kiekVartotoju > 0)
  39. {
  40. if (v2.getPsw().equals(v1.getPsw()))
  41. {
  42. System.out.println("viskas teisingai, prisijungete");
  43. }
  44. else
  45. {
  46. System.out.println("netinka psw");
  47. }
  48. }
  49. else
  50. {
  51. System.out.println("Nera tokio vartotojo");
  52. }
  53. }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement