To connect in Derby at home in your local desktop or laptop:
[Link] to Services
[Link] Databases -> select Java Db-> select create Database
You will get this screen.
Enter the database name, username, password and select ok
For ex: logindb,rose,123,123
3. In the above screen right click the blue selection and give
connect. Your database will be created.
4. Create table as shown below
[Link] creating Table go to javafx application and create a new
project and type the below code.
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
/**
* @author Rosy
*/
public class Loginjdbc extends Application {
Label l1,l2,l3;
TextField t1,t2;
PasswordField p1;
Button b1;
@Override
public void start(Stage primaryStage) {
// Button btn = new Button();
HBox h1 = new HBox();
HBox h2 = new HBox();
VBox root = new VBox();
[Link](200, 200);
Image i1 = new Image("[Link]");
Image i2 = new Image("[Link]");
ImageView iv1 = new ImageView(i1);
ImageView iv2= new ImageView(i2);
[Link](40);
[Link](40);
[Link](40);
[Link](40);
l1 = new Label("Login Page");
[Link](new Font(25));
[Link]([Link]);
t1 = new TextField();
[Link]("UserName");
[Link](170,170);
[Link]().addAll(iv1,t1);
p1= new PasswordField();
[Link](170,170);
[Link]().addAll(iv2,p1);
b1 = new Button("Login");
[Link](130,130);
[Link]().addAll(l1,h1,h2,b1);
[Link]([Link]);
[Link](new Insets(10));
[Link](10);
//[Link]();
Scene scene = new Scene(root, 300, 300);
[Link]([Link]);
[Link]().add(getClass().getResource("[Link]").toExternalForm());
[Link](new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// [Link]("Hello World!");
try
[Link]("[Link]");
Connection con =[Link]("jdbc:derby://localhost:1527/logindb",
"rose","rose");
PreparedStatement ps = [Link]("Insert into login1 values (?,?)");
[Link](1,([Link]()));
[Link](2,[Link]([Link]()));
int r = [Link]();
[Link]("r records inserted"+ r);
catch(Exception e)
[Link](e);
});
[Link]("Hello World!");
[Link](scene);
[Link]();
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
6. To run the program do the following :
A] add the css file.
B] add the person and human icon image or download some jpg
images from internet.
7. important point :
In libraries of loginjdbc project -> right click and select Add Library -> you will get below screen.
Choose Java DB driver and select Add Library.
Jar files will be added .
Now you can run the program and get the output as follows.
Try this and still any doubt ask tommorrow in college.
Similarly try for registration Page also:
Sample code and output:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package regjdbc;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
/**
*
* @author Rosy
*/
public class Regjdbc extends Application {
String butvalue=null;
@Override
public void start(Stage primaryStage) {
TextField t1,t2;
Label l1,l2,l3,l4,l5;
RadioButton r1,r2,r3;
ComboBox c1;
CheckBox cb1,cb2;
Button b1,b2,b3,b4;
ToggleGroup tg;
HBox h1,h2;
VBox root = new VBox();
Text tt1 = new Text("REGISTRATION PAGE");
[Link]([Link]("Arial",30));
[Link](100);
[Link](100);
// [Link]([Link]);
l1 = new Label("Name");
t1 = new TextField();
l2 = new Label("Age");
t2 = new TextField();
l3 = new Label("Gender");
h1 = new HBox();
cb1 = new CheckBox("Male");
cb2 = new CheckBox("Female");
[Link]().addAll(cb1,cb2);
l4 = new Label("Course");
tg = new ToggleGroup();
r1 = new RadioButton("Science");
[Link](tg);
r2 = new RadioButton("Arts");
[Link](tg);
r3 = new RadioButton("BCom");
[Link](tg);
[Link](new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
butvalue=[Link]();
}
});
[Link](new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
butvalue=[Link]();
}
});
[Link](new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
butvalue=[Link]();
}
});
h2 = new HBox();
[Link]().addAll(r1,r2,r3);
b1 = new Button("INSERT");
[Link](new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// [Link]("Hello World!");
String gen;
try
{
[Link]("[Link]");
Connection con
=[Link]("jdbc:derby://localhost:1527/logindb", "rose","rose");
PreparedStatement ps = [Link]("Insert into reg values (?,?,?,?)");
[Link](1,([Link]()));
[Link](2,[Link]([Link]()));
// to insert value from checkbox
if ([Link]())
gen = "MALE";
else
gen="FEMALE";
[Link](3,gen);
//to insert value from radiobutton
[Link](4,butvalue);
//[Link]("You are " + [Link]());
int r = [Link]();
[Link]("r records inserted"+ r);
}
catch(Exception e)
{
[Link](e);
}
}
});
[Link]().addAll(tt1,l1,t1,l2,t2,l3,h1,l4,h2,b1);
Scene scene = new Scene(root, 500,500);
[Link]("Hello World!");
[Link](scene);
[Link]();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Try adding combo box and listview also to this.