import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class StudentRegistration extends JFrame {

    StudentRegistration() {

        setTitle("Student Registration Form");
        setSize(400, 400);
        setLayout(new GridLayout(7, 2, 10, 10));

        JLabel nameLabel = new JLabel("Student Name:");
        JTextField nameField = new JTextField();

        JLabel rollLabel = new JLabel("Roll Number:");
        JTextField rollField = new JTextField();

        JLabel emailLabel = new JLabel("Email:");
        JTextField emailField = new JTextField();

        JLabel genderLabel = new JLabel("Gender:");
        JRadioButton male = new JRadioButton("Male");
        JRadioButton female = new JRadioButton("Female");

        ButtonGroup group = new ButtonGroup();
        group.add(male);
        group.add(female);

        JPanel genderPanel = new JPanel();
        genderPanel.add(male);
        genderPanel.add(female);

        JLabel courseLabel = new JLabel("Course:");
        String courses[] = {"B.Tech", "BCA", "MCA", "BBA"};
        JComboBox courseBox = new JComboBox<>(courses);

        JButton submit = new JButton("Submit");

        submit.addActionListener(e -> {
            String name = nameField.getText();
            String roll = rollField.getText();
            String email = emailField.getText();

            JOptionPane.showMessageDialog(this,
                "Registration Successful!\nName: " + name +
                "\nRoll No: " + roll +
                "\nEmail: " + email);
        });

        add(nameLabel);
        add(nameField);
        add(rollLabel);
        add(rollField);
        add(emailLabel);
        add(emailField);
        add(genderLabel);
        add(genderPanel);
        add(courseLabel);
        add(courseBox);
        add(new JLabel(""));
        add(submit);

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args) {
        new StudentRegistration();
    }
}




0-0-0-0-0-0-0-0-0




Definition:

JDBC stands for Java Database Connectivity. It is an API in Java that allows Java applications to connect and communicate with databases like MySQL, Oracle, and PostgreSQL.

It is used to insert, update, delete, and retrieve data from databases.


import java.sql.*;

public class DatabaseConnection {

    public static void main(String[] args) {

        try {
            // 1. Load Driver
            Class.forName("com.mysql.cj.jdbc.Driver");

            // 2. Establish Connection
            Connection con = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/college",
                "root",
                "password"
            );

            System.out.println("Database Connected Successfully!");

            // 3. Create Statement
            Statement stmt = con.createStatement();

            // 4. Execute Query
            ResultSet rs = stmt.executeQuery(
                "SELECT * FROM student"
            );

            // 5. Display Records
            while (rs.next()) {
                System.out.println(
                    rs.getInt("id") + " " +
                    rs.getString("name")
                );
            }

            // 6. Close Connection
            rs.close();
            stmt.close();
            con.close();

        } catch (Exception e) {
            System.out.println(e);
        }
    }
}




0-0-0-0-0-0-0-0-0-0




JSP stands for JavaServer Pages. It is a server-side technology used to create dynamic web pages using Java.

JSP allows developers to write HTML code along with Java code. It is mainly used to develop web applications that interact with databases and display dynamic content.



welcome.jsp




    JSP Example




    

Welcome to JSP

<% String name = "Sahil"; out.println("Hello " + name); %> Output: Welcome to JSP Hello Sahil