Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package app;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import javafx.application.Application;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.layout.GridPane;
- import javafx.stage.Stage;
- public class Przyklad2 extends Application {
- @Override
- public void start(Stage stage) {
- Label wynik = new Label("Połączono z bazą danych");
- Label err1= new Label("Błąd połączenia");
- Label err2= new Label("Błąd sterownika");
- GridPane okno = new GridPane();
- Button polacz = new Button("Połacz");
- okno.add(polacz,0,0,1,1);
- polacz.setOnAction(e->{
- okno.getChildren().remove(wynik);
- okno.getChildren().remove(err1);
- okno.getChildren().remove(err2);
- Connection con;
- try {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- con = DriverManager.getConnection("jdbc:sqlserver://"+
- "153.19.7.13 :1401;databaseName=jreclaw;"+
- "user=jreclaw;password=255094");
- okno.add(wynik,1,0,1,1);
- con.close();
- }
- catch(SQLException error_polaczenie) {
- okno.add(err1,1,0,1,1);}
- catch(ClassNotFoundException error_sterownik) {
- okno.add(err2,1,0,1,1);}
- });
- Scene scena = new Scene(okno,800,600);
- stage.setTitle("Nazwa programu");
- stage.setScene(scena);
- stage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement