import java.awt.*; import java.awt.event.*; import java.sql.*; public class StudentRegistrationDB extends Frame implements ActionListener { // Declare Components Label lblName, lblFather, lblDob, lblAddress, lblGender, lblQual, lblContact, lblEmail, lblBlood; TextField txtName, txtFather, txtContact, txtEmail; TextArea txtAddress; Choice dobDay, dobMonth, dobYear; CheckboxGroup genderGroup; Checkbox male, female; Checkbox chk10, chk12, chkUG; List bloodGroupList; Button btnSubmit; // Constructor public StudentRegistrationDB() { setTitle("Student Registration Form with Database"); setSize(500, 600); setLayout(null); setVisible(true); // Student Name lblName = new Label("Student Name:"); lblName.setBounds(50, 50, 120, 25); add(lblName); txtName = new TextField(); txtName.setBounds(200, 50, 200, 25); add(txtName); // Father Name lblFather = new Label("Father's Name:"); lblFather.setBounds(50, 90, 120, 25); add(lblFather); txtFather = new TextField(); txtFather.setBounds(200, 90, 200, 25); add(txtFather); // Date of Birth lblDob = new Label("Date of Birth:"); lblDob.setBounds(50, 130, 120, 25); add(lblDob); dobDay = new Choice(); for (int i = 1; i <= 31; i++) dobDay.add(String.valueOf(i)); dobDay.setBounds(200, 130, 50, 25); add(dobDay); dobMonth = new Choice(); String[] months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; for (String m : months) dobMonth.add(m); dobMonth.setBounds(260, 130, 70, 25); add(dobMonth); dobYear = new Choice(); for (int i = 1990; i <= 2025; i++) dobYear.add(String.valueOf(i)); dobYear.setBounds(340, 130, 60, 25); add(dobYear); // Address lblAddress = new Label("Address:"); lblAddress.setBounds(50, 170, 120, 25); add(lblAddress); txtAddress = new TextArea(); txtAddress.setBounds(200, 170, 200, 60); add(txtAddress); // Gender lblGender = new Label("Gender:"); lblGender.setBounds(50, 250, 120, 25); add(lblGender); genderGroup = new CheckboxGroup(); male = new Checkbox("Male", genderGroup, false); female = new Checkbox("Female", genderGroup, false); male.setBounds(200, 250, 60, 25); female.setBounds(270, 250, 70, 25); add(male); add(female); // Qualification lblQual = new Label("Qualification:"); lblQual.setBounds(50, 290, 120, 25); add(lblQual); chk10 = new Checkbox("10th"); chk12 = new Checkbox("12th"); chkUG = new Checkbox("UG"); chk10.setBounds(200, 290, 60, 25); chk12.setBounds(270, 290, 60, 25); chkUG.setBounds(340, 290, 60, 25); add(chk10); add(chk12); add(chkUG); // Contact Number lblContact = new Label("Contact No:"); lblContact.setBounds(50, 330, 120, 25); add(lblContact); txtContact = new TextField(); txtContact.setBounds(200, 330, 200, 25); add(txtContact); // Email lblEmail = new Label("Email ID:"); lblEmail.setBounds(50, 370, 120, 25); add(lblEmail); txtEmail = new TextField(); txtEmail.setBounds(200, 370, 200, 25); add(txtEmail); // Blood Group lblBlood = new Label("Blood Group:"); lblBlood.setBounds(50, 410, 120, 25); add(lblBlood); bloodGroupList = new List(5); String[] groups = {"A+", "A-", "B+", "B-", "O+", "O-", "AB+", "AB-"}; for (String g : groups) bloodGroupList.add(g); bloodGroupList.setBounds(200, 410, 100, 60); add(bloodGroupList); // Submit Button btnSubmit = new Button("Submit"); btnSubmit.setBounds(200, 490, 100, 30); btnSubmit.addActionListener(this); add(btnSubmit); // Window Close addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose(); } }); } @Override public void actionPerformed(ActionEvent e) { String name = txtName.getText(); String father = txtFather.getText(); String dob = dobDay.getSelectedItem() + "-" + dobMonth.getSelectedItem() + "-" + dobYear.getSelectedItem(); String address = txtAddress.getText(); String gender = genderGroup.getSelectedCheckbox() != null ? genderGroup.getSelectedCheckbox().getLabel() : ""; String qualification = ""; if (chk10.getState()) qualification += "10th "; if (chk12.getState()) qualification += "12th "; if (chkUG.getState()) qualification += "UG "; String contact = txtContact.getText(); String email = txtEmail.getText(); String blood = bloodGroupList.getSelectedItem(); // Database Insertion try { Class.forName("com.mysql.cj.jdbc.Driver"); Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/studentdb", "root", "yourpassword" ); String query = "INSERT INTO students (name, father_name, dob, address, gender, qualification, contact, email, blood_group) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; PreparedStatement pst = con.prepareStatement(query); pst.setString(1, name); pst.setString(2, father); pst.setString(3, dob); pst.setString(4, address); pst.setString(5, gender); pst.setString(6, qualification.trim()); pst.setString(7, contact); pst.setString(8, email); pst.setString(9, blood); int rows = pst.executeUpdate(); if (rows > 0) { Dialog d = new Dialog(this, "Success", true); d.setLayout(new FlowLayout()); d.add(new Label("Registration Successful!")); d.setSize(200, 100); d.setVisible(true); } pst.close(); con.close(); } catch (Exception ex) { ex.printStackTrace(); Dialog d = new Dialog(this, "Error", true); d.setLayout(new FlowLayout()); d.add(new Label("Error: " + ex.getMessage())); d.setSize(300, 100); d.setVisible(true); } } public static void main(String[] args) { new StudentRegistrationDB(); } }