Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.VBox;
- import javafx.stage.Stage;
- public class Login extends Application {
- @Override
- public void start(Stage primaryStage) {
- Label lbl1=new Label("User Name");
- TextField txt1=new TextField();
- Label lbl2=new Label("Password");
- TextField txt2=new TextField();
- Button btn = new Button("Login");
- btn.setScaleX(1);
- btn.setScaleY(1);
- btn.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- String query="Select * from user";
- System.out.println(query);
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con=DriverManager.getConnection("jdbc:mysql://www.db4free.net:3306/demo","demo","demo");//try your
- Statement stmt=con.createStatement();
- ResultSet rs=stmt.executeQuery(query);
- while(rs.next())
- System.out.println(rs.getString(1)+" "+rs.getString(2));
- con.close();
- }
- catch(Exception e){ System.out.println("\nError"+e);}
- }
- });
- VBox root = new VBox();
- root.getChildren().addAll(lbl1,txt1,lbl2,txt2,btn);
- Scene scene = new Scene(root, 600, 550);
- primaryStage.setTitle("User Login");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement