Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
39 views

Java Lab Answer 6

This document contains a JavaFX code assignment to create a login page with text fields to display a username and password retrieved from a database. It includes: 1) Java code to connect to a MySQL "details" database and retrieve username and password values from a "login" table 2) JavaFX code to create a login GUI with labels, text fields, and buttons laid out on a grid 3) The code populates the text fields with the username and password values from the database query

Uploaded by

adithkumar menon
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Java Lab Answer 6

This document contains a JavaFX code assignment to create a login page with text fields to display a username and password retrieved from a database. It includes: 1) Java code to connect to a MySQL "details" database and retrieve username and password values from a "login" table 2) JavaFX code to create a login GUI with labels, text fields, and buttons laid out on a grid 3) The code populates the text fields with the username and password values from the database query

Uploaded by

adithkumar menon
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

LAB ASSIGNMENT -6

NAME:ADITH KUMAR MENON


REGISTRATION NUMBER:18BCE2311

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);
}

}
}

OUTPUT OF THIS CODE:

JAVA FX CODE FOR CREATING THE TEXTFIELD TO DISPLAY THE


USERNAME AND PASSWORD

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;

public class Login extends Application {

public static void main(String[] args) {


launch(args);
}

@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));

Text scenetitle = new Text("Welcome");


scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
grid.add(scenetitle, 0, 0, 2, 1);

Label userName = new Label("User Name:");


grid.add(userName, 0, 1);

TextField userTextField = new TextField();


grid.add(userTextField, 1, 1);

Label pw = new Label("Password:");


grid.add(pw, 0, 2);

PasswordField pwBox = new PasswordField();


grid.add(pwBox, 1, 2);

Scene scene = new Scene(grid, 300, 275);


primaryStage.setScene(scene);
primaryStage.show();
}
}

OUTPUT:

The value that is shown in the database:\

You might also like