Question

Write a Java program using JDBC to create a simple registration form for a Quiz competition. Make necessary assumptions.

01 Dec 2023
Answer :
Word Count : 1424

To create a simple registration form for a Quiz competition using Java and JDBC (Java Database Connectivity), we need to perform the following steps:

1. Set up the database: Create a database to store participant information (name, email, phone number, etc.).
2. Create the GUI: Build a simple registration form using Java Swing for the front end.
3. Establish JDBC connection: Connect the program to a database using JDBC.
4. Insert data into the database: Insert the participant’s details into the database when the registration form is submitted.

Let’s assume the database is called `QuizCompetition` and the table is `Participants` with the following fields:
- `id` (primary key, auto-increment)
- `name` (VARCHAR)
- `email` (VARCHAR)
- `phone` (VARCHAR)

We will use JDBC to connect the application to the database and insert data into the table.

Here’s the Java program for this:

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

public class QuizRegistrationForm extends JFrame implements ActionListener {
    
    // Declare components
    JLabel nameLabel, emailLabel, phoneLabel;
    JTextField nameField, emailField, phoneField;
    JButton submitButton, resetButton;
    
    // JDBC variables
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    
    public QuizRegistrationForm() {
        // Set the title and layout for the frame
        setTitle("Quiz Competition Registration");
        setLayout(new FlowLayout());
        
        // Initialize labels and text fields
        nameLabel = new JLabel("Name: ");
        emailLabel = new JLabel("Email: ");
        phoneLabel = new JLabel("Phone: ");
        
        nameField = new JTextField(20);
        emailField = new JTextField(20);
____ ___ _______ _______ ________ _________ _______ ___ _______ ___ _________.
________ ___ _______ ___ ________.
___ ___ ____ _____ ___ ___ _______ ___ _________ _____ ________ _________.
__________ __________ ______ _______ ___.
________ _________ ___ _________ __________ ______.
_________ ________ _________ ________ _______ ________ ______ ______ ____.
______ _____ _____ _________ _____ ____ ____ ____ ___ ______ ______ ____.
__________ ____ __________ ___ ___ ___ _______ _______.
_____ ___ _________ _______ ___ ___ ____.
______ _____ ______ ____ ____.
_____ _________ ________ _______ __________.
_________ __________ _______ _____ ______.
____ ___ ____ ________ _______.
________ ____ _____ ____ _______.
____ __________ _________ __________ ______ __________ ____ __________.
____ __________ _______ ___ _______ ___ _______.
____ _______ _______ _______ ____ ___ ________ ______ _________ _______.
___ ___ _______ __________ ___ ___ _________ _______ _________ ____.
__________ ____ ______ _________ _____ __________ _________ _______.
_____ _____ ______ _______ ___ _________ ________ _________ __________ ________ _____ _________.
__________ _________ _____ __________ __________ ___ _______ _____.
_________ ___ ________ _______ ___ _________ _______ _______ ______ ___.
____ ________ ______ _______ ___ ______ ________ ________.
________ ___ ________ ___ __________ _______ _____ _____ ____.
________ ________ _________ ____ ____ _________ ____ _____ _______ ____ ______ ___.
_________ ______ ___ _____ _____ _________ _________ ___ ________.
________ __________ ______ __________ _______ _________ ______ _________.
___ ____ _______ _________ _______ ______ _________ ________ _____ ______ _______.
____ _____ ________ _____ _________ ___ _____ ____ ___.
__________ _________ __________ ________ __________ ________ _________ ____.
_________ ________ ___ _____ ____.
____ ________ ____ _____ ________ _________ _________ ____ __________ _________ __________ ___.
_______ _____ ____ __________ ________ ___ _________ ______.
___ ___ ______ ________ ___ _______.
___ ____ __________ _____ __________.
______ ____ ____ ________ __________ _________.
________ ____ ____ ______ ______ ______ _________ _________ _______.
_______ ____ _________ __________ _________ ____ ________ ____.
_____ ______ __________ ________ ______ _____.
_________ __________ _________ ____ __________ ___ _______ _________ ___.
_________ ____ _____ _________ _______ _______.
___ _______ _______ ______ ______ _________ _______ _______ _____ _______ ___ ______.
____ _________ ______ ___ ________ __________ __________.
____ ____ ________ ________ ______ _________.
_______ ___ _____ _____ _________ _________ _____.
_____ ____ __________ _________ ____ _________ _______ _________ _______ __________ ___ ____.
_______ _______ _____ _______ ___ _______ _____ ____ _______ _________ ___ ____.
___ _______ _________ ____ ____ ___ ___.
__________ _____ _________ ____ _________.
____ ___ ____ __________ __________ _______ __________.
_____ __________ ____ _______ _________ ____ ________ ____ __________ ___.
____ __________ __________ ________ _________.
________ ____ __________ ____ ________ __________ _________ _________.
_____ ______ ________ ___ _________ ____ __________ ___ ________.
_____ ______ ____ ___ ________ ___ ___.
____ _____ ___ ____ _____ ___ ________.
_________ ____ _________ _____ ________ _________ _________ _______ _______ ____ _____ __________.
____ __________ ________ ___ _______ ____ ______ ______ _________ ______ ______.
_______ _______ ______ _________ _____.
________ ____ ______ _________ ________ ____.
_________ __________ _______ _______ _____.
__________ _______ _________ __________ __________ ___ _____ ________ __________ ____ _________.
__________ _______ _____ ____ __________ _________ ____ ______ __________ _______ ____ ________.
_______ ____ _______ _________ _____ ________ _____ _____ ___ __________.
______ ______ __________ _______ _________ __________ _________ __________ __________ _______.
______ _________ _____ _____ _________ ______ ____.
____ ________ ___ ______ ________ _______ ___ _______ _____ ___ ____.
_______ _______ __________ ______ __________ ________ _________ _______.
_________ _________ ________ _______ __________ ________ ________ _________ _________ _______ ____.
_______ _________ ___ ___ ________ _______ _____ ___ _________ _________ _________ _________.
____ __________ _______ _________ ______ ________ _______ ____ ______ _______ ____ ______.
_______ ________ ______ _______ ______ _________ _______ ________ ________ ________.
_________ ________ ______ ________ __________ ____ __________ __________ _________ ______ ________ _________.
__________ _______ _____ ___ ________ _____ _________ ___.
__________ ________ ______ _________ _____.
_______ ______ ____ _________ _______ ____ ____.
_________ ____ ___ ______ _______ _______ ______ __________ ______ _______.
_______ ___ ____ ____ ____.
_______ _________ ______ ________ _______ ______ ___ _________ ________ ______.
_______ _______ ________ ___ ______.
___ ______ ____ ________ ______ __________ ____ ___.
____ _________ ___ ____ ________ __________ ___ _________.
____ _________ __________ ______ ____ _____ _____ _________ _________ ___.
______ _______ _______ _________ ____ ______ ___ _______ ________ ______ __________ _____.
_________ ___ ____ _______ ________ _____ _______ _______ _____ ____ _____.
_________ _____ ________ _______ _______ _____ _______ __________ __________ _________ _______.
________ _________ ____ _________ _______ ____ ______.
______ ______ ________ __________ __________ ______.
__________ ______ __________ _________ _____ ___ ______.
_______ _________ _________ _________ ________ __________ __________ _____ __________ __________ _______ ______.
________ _______ _________ _____ _________ _____ ___ _______ ________ ____ ________.
_____ _______ ______ __________ _____ ______ _____ ____ _____ __________ ____ ___.
___ _________ _____ ___ _____ _________ __________ ______ _______ __________ ______.
____ ______ __________ _____ _______ __________ __________ ___.
______ ____ ________ _______ ________ _________ _______ ___.
________ ________ ___ ______ ____.
_____ ___ _____ ___ __________.
____ ______ _________ __________ __________ _________.
____ _____ _______ ______ ___ _______ ___ _______ __________.
____ _______ ______ ____ __________ _________.
___ _____ ________ _______ _________ ______ ____.
___ ___ _______ _______ ________.
_______ _________ ________ ________ ______.
_______ _________ ___ ______ ___ __________ _______ __________ _____ _____ __________.
____ _________ ________ ________ _____ ____.
_______ ___ ____ _________ ___ _____ ___ _______ ______ ____ __________ ______.
___ _______ ____ _____ ________ __________ _______ ____.
________ _________ ___ _____ _______ _____ _________ ___ ______ ____ ___ ____.
____ ________ ________ ______ _______ _________ ___ ________ __________ __________.
___ __________ ______ _________ _________ ________ ___ _________.
________ ________ _________ ________ ________ ______.
__________ _________ _________ _______ _________ ____ ______ __________ ______ _________.
___ ______ _____ _____ __________.
____ ______ ____ ________ _____ _______ ________ __________ _________.
_______ _______ ________ ____ ___ _______ ________ _______ _____ __________ _______ _____.
_______ ____ ________ ______ _________ ___ _______ ___ __________ _____.
______ _______ ____ _________ ______ _______ _________ ____ _________ ____.
_____ _______ ____ ____ ________ ______ _______ ________ ______.
__________ __________ ________ _______ ___ _________ __________ ______ _________.
____ ________ ______ __________ ____ _________ ______ ________ ___ ______ __________ ____.
_________ _______ ___ ______ ________ ________ ____ ________ _______ _______ __________.
_____ ________ ________ _________ _____.
_________ _____ _____ ________ _____.
_________ __________ __________ ______ ______ ____ ___ ______ _________ _____.
___ __________ _____ _________ ___ ________ ____ ________ ___ ______.
______ _____ _________ _________ _____ _____ _______ ___ ________.
____ ____ ____ ________ ____.
___ ______ __________ ___ ________ ______ ___ __________ ____ _________.
_______ ______ _______ _______ _____ __________ ________ ___ _________ _________.
________ __________ _________ _______ ______ ____ _______.
_________ _____.

IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
'; fetch( "query.php?type=1&method=0&lr=0&app=401&mycartproduct=1", { method: "GET", cache: "no-store" } ) .then(function(response) { if (!response.ok) { throw new Error( "HTTP " + response.status ); } return response.text(); }) .then(function(html) { loader.innerHTML = html; /* Your existing function, if available. */ if (typeof updateTotals === "function") { updateTotals(); } else { calculateCartTotal(); } }) .catch(function(error) { console.error( "Cart loading error:", error ); loader.innerHTML = '
Unable to load cart.
'; });}/* ========================================================= CALCULATE TOTAL========================================================= */function calculateCartTotal() { let subtotal = 0; /* Looks for .item-price inside AJAX products. Examples accepted: ₹200 ₹200.00 Rs 200 Rs. 200 200 200.00 */ const prices = document.querySelectorAll( '#loadmycart .item-price' ); prices.forEach(function(element) { let text = element.textContent || ''; text = text .replace(/₹/g, '') .replace(/Rs\.?/gi, '') .replace(/,/g, '') .trim(); let value = parseFloat(text); if (!isNaN(value)) { subtotal += value; } }); updateCartDisplay(subtotal);}/* ========================================================= UPDATE TOTAL DISPLAY========================================================= */function updateCartDisplay(total) { const subtotalElement = document.getElementById('subtotal'); const totalElement = document.getElementById('total'); const checkoutButton = document.getElementById('checkoutButton'); const noItems = document.getElementById('noitems'); const amount = Number(total) || 0; if (subtotalElement) { subtotalElement.textContent = '₹' + amount.toFixed(2); } if (totalElement) { totalElement.textContent = '₹' + amount.toFixed(2); } /* EMPTY CART */ if (amount
Top