Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package baza;
- import java.net.URL;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ResourceBundle;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- /**
- *
- * @author nowak_000
- */
- public class FXMLDocumentController implements Initializable {
- @FXML
- private TextField login;
- @FXML
- private TextField haslo;
- @FXML
- private TextField imie;
- @FXML
- private TextField nazwisko;
- @FXML
- private Button zaloguj;
- @FXML
- private Button dodaj;
- @FXML
- private Button exit;
- @FXML
- private Label info;
- @FXML
- private Label labelGlowny;
- @FXML
- private void handleButtonAction(ActionEvent event) {
- String Login = login.getText();
- String Haslo = haslo.getText();
- if("1".equals(Login) && "2".equals(Haslo)){
- info.setText("Jesteś zalogowany");
- Connection con;
- Statement st;
- ResultSet rs;
- String url = "jdbc:mysql://localhost/uzytkownik"; //w miejscu kropek należy podać nazwę bazy
- String user = "root";
- String pass = "lukasz" ;//tu należy podać hasło
- try {
- String IMIE = imie.getText();
- String NAZWISKO = nazwisko.getText();
- con = DriverManager.getConnection(url, user, pass);
- st = con.createStatement();
- rs = st.executeQuery("SELECT * FROM osoba"); //zapytanie SQL
- while (rs.next()) {
- labelGlowny.setText(rs.getString(1) + " " + rs.getString(2));
- }
- } catch (SQLException e){
- System.out.println("błąd SQL");
- }
- }
- else{
- info.setText("Nie prawidłowe dane logowania");
- }
- }
- @FXML
- private void handleButtonexit(ActionEvent event) {
- System.exit(0);
- }
- @FXML
- private void handleButtonDodaj(ActionEvent event) {
- System.exit(0);
- }
- @FXML
- private void handleButtonSortuj(ActionEvent event) {
- System.exit(0);
- }
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- // TODO
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement