Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. package app;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. import javafx.application.Application;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.Button;
  10. import javafx.scene.control.Label;
  11. import javafx.scene.layout.GridPane;
  12. import javafx.stage.Stage;
  13.  
  14. public class Przyklad2 extends Application {
  15. @Override
  16. public void start(Stage stage) {
  17. Label wynik = new Label("Połączono z bazą danych");
  18. Label err1= new Label("Błąd połączenia");
  19. Label err2= new Label("Błąd sterownika");
  20. GridPane okno = new GridPane();
  21. Button polacz = new Button("Połacz");
  22. okno.add(polacz,0,0,1,1);
  23. polacz.setOnAction(e->{
  24. okno.getChildren().remove(wynik);
  25. okno.getChildren().remove(err1);
  26. okno.getChildren().remove(err2);
  27. Connection con;
  28. try {
  29. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  30. con = DriverManager.getConnection("jdbc:sqlserver://"+
  31. "153.19.7.13 :1401;databaseName=jreclaw;"+
  32. "user=jreclaw;password=255094");
  33. okno.add(wynik,1,0,1,1);
  34. con.close();
  35.  
  36. }
  37. catch(SQLException error_polaczenie) {
  38. okno.add(err1,1,0,1,1);}
  39. catch(ClassNotFoundException error_sterownik) {
  40. okno.add(err2,1,0,1,1);}
  41.  
  42. });
  43. Scene scena = new Scene(okno,800,600);
  44. stage.setTitle("Nazwa programu");
  45. stage.setScene(scena);
  46. stage.show();
  47.  
  48. }
  49. public static void main(String[] args) {
  50. launch(args);
  51.  
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement