Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package abdfx2;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.ResultSetMetaData;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.regex.Pattern;
- import javafx.application.Application;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.ScrollPane;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.VBox;
- import javafx.stage.Stage;
- public class Przychodnia extends Application {
- Connection con;
- int kolumny;
- public void start(Stage stage) throws Exception {
- Label wynik= new Label("Polaczono z bd");
- Label err1= new Label("Blad polaczenia z bd");
- Label err2= new Label("Blad sterownika");
- String lekarz= "select nazwisko, specjalizacja, nr_pokoju from lekarz";
- Label pacjent= new Label("select p.nazwisko");
- TextField tf= new TextField();
- // Label spisLekarzy;
- GridPane okno= new GridPane();
- ScrollPane Sp = new ScrollPane();
- Sp.setPrefSize(400, 400);
- VBox lewy=new VBox();
- //lewy.setMinWidth(200);
- lewy.setAlignment(Pos.TOP_LEFT);
- lewy.setMinWidth(200);
- okno.add(lewy, 0, 0, 1, 3);
- HBox prawy= new HBox();
- prawy.setMinWidth(200);
- prawy.setAlignment(Pos.TOP_LEFT);
- Sp.setContent(prawy);
- okno.add(prawy,0, 4, 1, 4);
- Button polaczenie= new Button("Polacz z baza");
- polaczenie.setMinSize(200, 30);
- Button lekarze= new Button("Sprawdz lekarzy");
- lekarze.setMinSize(200, 30);
- Button wizyty= new Button("Znajdz");
- Button szukajka= new Button("Szukaj wizyte");
- szukajka.setMinSize(200, 30);
- wizyty.setMinSize(200, 30);
- try {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- con = DriverManager.getConnection("jdbc:sqlserver://"+
- "153.19.7.13:1401;databaseName=mchudzinski;"+
- "user=mchudzinski;password=253748;");
- Statement zap= con.createStatement();
- String res = "";
- ResultSet wynik_zapytania = zap.executeQuery(lekarz);
- ResultSetMetaData ile_kol= wynik_zapytania.getMetaData();
- kolumny= ile_kol.getColumnCount();
- zap.close();
- con.close();
- }
- catch(SQLException error_polaczenie){}
- catch(ClassNotFoundException error_sterownik) {}
- VBox[] vBoxes=new VBox[kolumny];
- for (int i=0;i<vBoxes.length;i++) {
- vBoxes[i]= new VBox();
- vBoxes[i].setPrefSize(200, 200);
- }
- lewy.getChildren().addAll(polaczenie, lekarze, szukajka);
- szukajka.setOnAction(e->{
- prawy.getChildren().clear();
- okno.getChildren().remove(Sp);
- okno.add(Sp, 1, 0, 1, 1);
- prawy.getChildren().addAll(tf,wizyty);
- });
- wizyty.setOnAction(e -> {
- prawy.getChildren().clear();
- okno.getChildren().remove(Sp);
- okno.add(Sp, 1, 0, 1, 1);
- try {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- con = DriverManager.getConnection("jdbc:sqlserver://"+
- "153.19.7.13:1401;databaseName=mchudzinski;"+
- "user=mchudzinski;password=253748;");
- Statement zap= con.createStatement();
- String nazw="SELECT pacjent.nazwisko, wizyta.data_wizyty, lekarz.nazwisko, lekarz.specjalizacja, lekarz.nr_pokoju FROM wizyta LEFT JOIN pacjent on wizyta.id_pacjent = pacjent.id_pacjent LEFT JOIN lekarz on wizyta.id_lekarz = lekarz.id_lekarz where pacjent.nazwisko='"+tf.getText()+"'";
- ResultSet wynik_zapytania = zap.executeQuery(nazw);
- int i=1;
- String spr="";
- while(wynik_zapytania.next()) {
- spr=spr+wynik_zapytania.getString(1)+" "+wynik_zapytania.getString(2)+" "+wynik_zapytania.getString(3)
- +" "+wynik_zapytania.getString(4)+" "+wynik_zapytania.getString(5)+"\n";
- i++;
- }
- Label lab= new Label(spr);
- prawy.getChildren().addAll(lab);
- zap.close();
- con.close();
- }
- catch(SQLException error_polaczenie){
- System.out.println("pol");
- }
- catch(ClassNotFoundException error_sterownik) {}
- });
- polaczenie.setOnAction(e-> {
- prawy.getChildren().clear();
- okno.getChildren().remove(Sp);
- okno.add(Sp, 1, 0, 1, 1);
- try{
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- con = DriverManager.getConnection("jdbc:sqlserver://"+
- "153.19.7.13:1401;databaseName=mchudzinski;"+
- "user=mchudzinski;password=253748;");
- prawy.getChildren().add(wynik);
- }
- catch(SQLException error_polaczenie) {
- prawy.getChildren().add(err1);
- }
- catch(ClassNotFoundException error_sterownik) {
- prawy.getChildren().add(err2);
- }
- });
- lekarze.setOnAction(e->{
- prawy.getChildren().clear();
- okno.getChildren().remove(Sp);
- prawy.getChildren().addAll(vBoxes);
- okno.add(Sp, 1, 0, 1, 1);
- for(int i=0;i<vBoxes.length;i++) {
- vBoxes[i].getChildren().clear();
- }
- try {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- con = DriverManager.getConnection("jdbc:sqlserver://"+
- "153.19.7.13:1401;databaseName=mchudzinski;"+
- "user=mchudzinski;password=253748;");
- Statement zap= con.createStatement();
- ResultSet wynik_zapytania = zap.executeQuery(lekarz);
- while(wynik_zapytania.next())
- {
- int i=1, j;
- for(j=0;j<vBoxes.length;j++) {
- Label col=new Label(wynik_zapytania.getString(i));
- vBoxes[j].getChildren().add(col);
- i++;
- }
- }
- zap.close();
- con.close();
- }
- catch(SQLException error_polaczenie){}
- catch(ClassNotFoundException error_sterownik) {}
- });
- Scene scena= new Scene(okno, 800, 600);
- stage.setScene(scena);
- stage.show();
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Application.launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement