Java Lab Answer 6
Java Lab Answer 6
Q1: Write a JavaFX to show the username and password in textboxes available in a
“login” database
ANS:
CONNECTION TO JDBC:
import java.sql.*;
class demo {
public static void main(String[] args){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/details","adith", "1234");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from login");
while (rs.next())
System.out.println(rs.getString( 1) + " " + rs.getString( 2));
con.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
package login;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("JavaFX Welcome");
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
OUTPUT: