Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import javafx.application.Application;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.*;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.VBox;
- import javafx.stage.Stage;
- import java.sql.*;
- public class Main2 extends Application {
- Connection con;
- @Override
- public void start(Stage primaryStage) throws Exception{
- Menu m = new Menu("MENU");
- MenuItem mi1 = new MenuItem("Połączenie");
- MenuItem mi2 = new MenuItem("lekarze");
- MenuItem mi3 = new MenuItem("Wizyta");
- m.getItems().addAll(mi1,mi2,mi3);
- MenuBar menubar = new MenuBar();
- menubar.getMenus().add(m);
- menubar.setMaxWidth(85);
- //Przyciski
- GridPane container = new GridPane();
- VBox left = new VBox(80);
- left.setMinSize(200,600);
- left.setAlignment(Pos.TOP_LEFT);
- VBox right = new VBox(10);
- right.setMinSize(600,600);
- right.setAlignment(Pos.CENTER);
- VBox response = new VBox(20);
- response.setAlignment(Pos.TOP_CENTER);
- response.setMinSize(500,300);
- Label l1 = new Label();
- TextField t1 = new TextField();
- Button bt1 = new Button("Szukaj");
- bt1.setOnAction(e -> {
- response.getChildren().clear();
- try
- {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- con = DriverManager.getConnection("jdbc:sqlserver://"+
- "153.19.7.13:1401;databaseName=aborawski;"+
- "user=aborawski;password=254121;");
- Statement zapyt = con.createStatement();
- String sql="select Dzien,Godzina,Pacjent.Nazwisko,Lekarz.Nazwisko from Rejestracja join Pacjent on Rejestracja.ID_Pacjent = Pacjent.ID join Lekarz on Rejestracja.ID_Lekarz = Lekarz.ID where Pacjent.Nazwisko = '" + t1.getText() + "'";
- ResultSet wynik_zapyt = zapyt.executeQuery(sql);
- while(wynik_zapyt.next())
- {
- Label l2 = new Label(" | " +wynik_zapyt.getString(1) + " ;; " + wynik_zapyt.getString(2) + " | " + wynik_zapyt.getString(3)+ " | "+ wynik_zapyt.getString(4)+ " | ");
- response.getChildren().add(l2);
- }
- zapyt.close();
- con.close();
- }
- catch(SQLException sqle) {
- System.out.println(sqle);}
- catch(ClassNotFoundException d) {
- System.out.println("Brak sterownika");}
- });
- mi1.setOnAction(e -> {
- try
- {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- con = DriverManager.getConnection("jdbc:sqlserver://"+
- "153.19.7.13:1401;databaseName=aborawski;"+
- "user=aborawski;password=254121;");
- l1.setText("Połączono z bazą danych");
- right.getChildren().clear();
- right.getChildren().add(l1);
- con.close();
- }
- catch(SQLException sqle) {
- l1.setText("Błąd połączenia");
- right.getChildren().clear();
- right.getChildren().add(l1);}
- catch(ClassNotFoundException d) {
- l1.setText("Brak Sterownika");
- right.getChildren().clear();
- right.getChildren().add(l1);}
- });
- mi2.setOnAction(e -> {
- right.getChildren().clear();
- int ile=0;
- try
- {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- con = DriverManager.getConnection("jdbc:sqlserver://"+
- "153.19.7.13:1401;databaseName=aborawski;"+
- "user=aborawski;password=254121;");
- Statement zapyt = con.createStatement();
- String sql="select * from Lekarz";
- ResultSet wynik_zapyt = zapyt.executeQuery(sql);
- ResultSetMetaData wynik_kol = wynik_zapyt.getMetaData();
- ile= wynik_kol.getColumnCount();
- while(wynik_zapyt.next())
- {
- Label l2 = new Label(" | " +wynik_zapyt.getString(3) + " | " + wynik_zapyt.getString(4)+ " | ");
- right.getChildren().add(l2);
- }
- zapyt.close();
- con.close();
- }
- catch(SQLException sqle) {
- System.out.println(sqle);}
- catch(ClassNotFoundException d) {
- System.out.println("Brak sterownika");}
- });
- mi3.setOnAction(e -> {
- right.getChildren().clear();
- HBox h1 = new HBox();
- h1.setAlignment(Pos.CENTER);
- h1.getChildren().addAll(t1,bt1);
- right.getChildren().addAll(h1,response);
- });
- left.getChildren().addAll(menubar);
- container.add(right,1,0);
- container.add(left,0,0);
- primaryStage.setTitle("Hello World");
- primaryStage.setScene(new Scene(container, 800, 600));
- primaryStage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- /*try
- {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- con = DriverManager.getConnection("jdbc:sqlserver://"+
- "153.19.7.13:1401;databaseName=aborawski;"+
- "user=aborawski;password=254121;");
- Statement zapyt = con.createStatement();
- String sql="select * from waga";
- ResultSet wynik_zapyt = zapyt.executeQuery(sql);
- ResultSetMetaData wynik_kol = wynik_zapyt.getMetaData();
- zapyt.close();
- con.close();
- }
- catch(SQLException sqle) {
- System.out.println(sqle);}
- catch(ClassNotFoundException e) {
- System.out.println("Brak sterownika");}
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement