Advertisement
Guest User

Untitled

a guest
Jan 25th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package baza;
  7.  
  8. import java.net.URL;
  9. import java.sql.Connection;
  10. import java.sql.DriverManager;
  11. import java.sql.ResultSet;
  12. import java.sql.SQLException;
  13. import java.sql.Statement;
  14. import java.util.ResourceBundle;
  15. import javafx.event.ActionEvent;
  16. import javafx.fxml.FXML;
  17. import javafx.fxml.Initializable;
  18. import javafx.scene.control.Button;
  19. import javafx.scene.control.Label;
  20. import javafx.scene.control.TextField;
  21.  
  22. /**
  23. *
  24. * @author nowak_000
  25. */
  26. public class FXMLDocumentController implements Initializable {
  27.  
  28. @FXML
  29. private TextField login;
  30. @FXML
  31. private TextField haslo;
  32. @FXML
  33. private TextField imie;
  34. @FXML
  35. private TextField nazwisko;
  36. @FXML
  37. private Button zaloguj;
  38. @FXML
  39. private Button dodaj;
  40. @FXML
  41. private Button exit;
  42. @FXML
  43. private Label info;
  44. @FXML
  45. private Label labelGlowny;
  46.  
  47. @FXML
  48. private void handleButtonAction(ActionEvent event) {
  49. String Login = login.getText();
  50. String Haslo = haslo.getText();
  51. if("1".equals(Login) && "2".equals(Haslo)){
  52. info.setText("Jesteś zalogowany");
  53. Connection con;
  54. Statement st;
  55. ResultSet rs;
  56. String url = "jdbc:mysql://localhost/uzytkownik"; //w miejscu kropek należy podać nazwę bazy
  57. String user = "root";
  58. String pass = "lukasz" ;//tu należy podać hasło
  59. try {
  60. String IMIE = imie.getText();
  61. String NAZWISKO = nazwisko.getText();
  62. con = DriverManager.getConnection(url, user, pass);
  63. st = con.createStatement();
  64. rs = st.executeQuery("SELECT * FROM osoba"); //zapytanie SQL
  65. while (rs.next()) {
  66. labelGlowny.setText(rs.getString(1) + " " + rs.getString(2));
  67. }
  68. } catch (SQLException e){
  69. System.out.println("błąd SQL");
  70. }
  71.  
  72.  
  73.  
  74. }
  75. else{
  76. info.setText("Nie prawidłowe dane logowania");
  77. }
  78. }
  79.  
  80. @FXML
  81. private void handleButtonexit(ActionEvent event) {
  82. System.exit(0);
  83. }
  84.  
  85. @FXML
  86. private void handleButtonDodaj(ActionEvent event) {
  87. System.exit(0);
  88. }
  89.  
  90. @FXML
  91. private void handleButtonSortuj(ActionEvent event) {
  92. System.exit(0);
  93. }
  94.  
  95.  
  96. @Override
  97. public void initialize(URL url, ResourceBundle rb) {
  98. // TODO
  99. }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement