Skip to content

About

A Java-based Online Voting System using JDBC and MySQL, featuring voter registration, authentication, candidate management, secure vote submission, duplicate-voting prevention, and election result tracking.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ—ณ๏ธ Online Voting System

A Java-based Online Voting System built with Core Java, JDBC, and MySQL to manage voter registration, authentication, candidate management, vote submission, and election result tracking.

The project demonstrates practical implementation of Java programming, object-oriented concepts, database connectivity, SQL queries, and CRUD operations.


๐Ÿ“Œ Project Overview

The Online Voting System is a console-based application designed to provide a structured digital voting process.

It allows voters to register, log in, view their profiles, and cast their votes for available candidates. An administrator can log in separately to add candidates and view election results.

The application uses Java Database Connectivity (JDBC) to communicate with a MySQL database and store voter information, candidate details, and voting records.

โœจ Features

๐Ÿ‘ค Voter Module

  • Voter Registration: Register voters with personal and identification details.
  • Input Validation: Validate voter ID, Aadhaar number, phone number, email, and password format.
  • Voter Authentication: Log in using registered email and password.
  • Cast Vote: View available candidates and submit a vote.
  • Duplicate Voting Prevention: Check whether a voter has already voted.
  • View Profile: Retrieve registered voter information.

๐Ÿ” Administrator Module

  • Admin Authentication: Separate administrator login.
  • Add Candidates: Register candidates with their names and political party details.
  • View Election Results: Display candidate-wise vote counts.
  • Candidate Management: Store and retrieve candidate information using MySQL.

๐Ÿ—„๏ธ Database Features

  • MySQL database integration using JDBC.
  • Prepared statements for parameterized SQL queries.
  • Relational data storage for voters, candidates, administrators, and votes.
  • SQL JOIN and aggregate functions for election result calculation.

๐Ÿ› ๏ธ Technology Stack

Technology Purpose
Java Application development
JDBC Database connectivity
MySQL Relational database
MySQL Connector/J JDBC driver
IntelliJ IDEA Development environment

Core Java Concepts Used

  • Object-Oriented Programming (OOP)
  • Classes and methods
  • Conditional statements and switch expressions
  • Loops and exception handling
  • Scanner for user input
  • Regular expressions for input validation

Database Concepts Used

  • SQL INSERT, SELECT, and UPDATE
  • PreparedStatement
  • ResultSet
  • INNER and LEFT JOIN concepts
  • COUNT() and GROUP BY
  • Database constraints

๐Ÿ“‚ Project Structure

OnlineVotingSystem/
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ Main.java
โ”‚
โ”œโ”€โ”€ .idea/
โ”‚
โ”œโ”€โ”€ .gitignore
โ”‚
โ””โ”€โ”€ OnlineVotingSystem.iml

โš™๏ธ Prerequisites

Before running the application, make sure you have installed:

  • Java JDK 14 or later
  • MySQL Server 8.0 or compatible version
  • MySQL Connector/J
  • IntelliJ IDEA or another Java IDE

๐Ÿš€ Installation & Setup

1. Clone the Repository

git clone https://github.com/ItsHardikSoni/OnlineVotingSystem.git

2. Navigate to the Project Directory

cd OnlineVotingSystem

3. Create the MySQL Database

Open MySQL Workbench or your MySQL terminal and execute:

CREATE DATABASE voting_system;

USE voting_system;

4. Create the Required Tables

Voters Table

CREATE TABLE voters (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(100) UNIQUE NOT NULL,
    number VARCHAR(15) NOT NULL,
    state VARCHAR(100),
    aadhaar VARCHAR(12) NOT NULL,
    password VARCHAR(255) NOT NULL,
    voter_id VARCHAR(10) UNIQUE NOT NULL,
    has_voted BOOLEAN DEFAULT FALSE
);

Candidates Table

CREATE TABLE candidates (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    party VARCHAR(100) NOT NULL
);

Votes Table

CREATE TABLE votes (
    id INT AUTO_INCREMENT PRIMARY KEY,
    voter_id INT NOT NULL,
    candidate_id INT NOT NULL,

    FOREIGN KEY (voter_id) REFERENCES voters(id),
    FOREIGN KEY (candidate_id) REFERENCES candidates(id)
);

Admin Table

CREATE TABLE admin (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) UNIQUE NOT NULL,
    password VARCHAR(255) NOT NULL
);

5. Insert an Administrator Account

INSERT INTO admin (username, password)
VALUES ('admin', 'CHANGE_THIS_PASSWORD');

Replace the example password with your own development password.

6. Configure Database Connection

Open src/Main.java and locate the database configuration:

static final String DB_URL =
    "jdbc:mysql://127.0.0.1:3306/voting_system";

static final String USER = "root";
static final String PASS = "YOUR_MYSQL_PASSWORD";

Update the username and password according to your local MySQL configuration.

Important: Never commit real database credentials to a public repository. Use environment variables or an external configuration file.

7. Add MySQL Connector/J

Download MySQL Connector/J:

https://dev.mysql.com/downloads/connector/j/

Add the downloaded JAR file to your project's dependencies or classpath.

8. Run the Application

Open Main.java in IntelliJ IDEA and execute the main() method.


๐Ÿ–ฅ๏ธ Application Menu

When the application starts, the following menu appears:

================================
       ONLINE VOTING SYSTEM
================================

1. Voter Registration
2. Voter Login & Vote
3. View Profile
4. Admin Login
5. Exit

Choose an option:

Voter Workflow

Start Application
       |
       v
Voter Registration
       |
       v
Enter Personal Details
       |
       v
Input Validation
       |
       v
Save Voter Information
       |
       v
Voter Login
       |
       v
View Available Candidates
       |
       v
Cast Vote
       |
       v
Update Voting Status

Administrator Workflow

Admin Login
     |
     v
Validate Credentials
     |
     v
Admin Dashboard
     |
     +----------------------+
     |                      |
     v                      v
 Add Candidate         View Results
     |                      |
     v                      v
Save Candidate         Count Votes
     |                      |
     v                      v
Return to Menu         Display Results

๐Ÿ—ƒ๏ธ Database Operations

The application performs several database operations using JDBC.

Operation SQL Concept
Voter registration INSERT
Voter authentication SELECT
View voter profile SELECT
Cast vote INSERT
Update voting status UPDATE
Add candidate INSERT
Calculate election results LEFT JOIN, COUNT(), GROUP BY

Example: Election Result Query

The following query retrieves the number of votes received by each candidate:

SELECT
    candidates.name,
    candidates.party,
    COUNT(votes.id) AS vote_count
FROM candidates
LEFT JOIN votes
    ON candidates.id = votes.candidate_id
GROUP BY candidates.id;

๐Ÿ”’ Security & Development Considerations

This project is an educational implementation demonstrating database-driven voting workflows. It is not a production-ready electronic voting platform.

Some important improvements for a production system include:

  • Secure password hashing instead of storing plaintext passwords.
  • Environment-based database credential management.
  • Database transactions for atomic vote submission.
  • Stronger authentication and authorization.
  • Protection against concurrent duplicate voting.
  • Privacy protection for sensitive voter information.
  • Independent security auditing and election integrity verification.

Note: The current implementation uses basic validation and a voter status flag. These mechanisms alone do not provide the security guarantees required for real-world elections.


๐Ÿ”ฎ Future Enhancements

  • Develop a graphical user interface using Java Swing or JavaFX.
  • Implement secure password hashing.
  • Add database transaction management.
  • Introduce candidate search and filtering.
  • Generate downloadable election result reports.
  • Improve admin and voter authorization.
  • Add comprehensive validation and exception handling.

๐ŸŽฏ Learning Outcomes

Through this project, I practiced:

  • Applying Core Java and OOP concepts.
  • Connecting Java applications with MySQL using JDBC.
  • Writing SQL queries for relational databases.
  • Implementing authentication and registration workflows.
  • Working with PreparedStatement and ResultSet.
  • Handling database exceptions and user input validation.
  • Building a complete database-driven console application.

๐Ÿ‘จโ€๐Ÿ’ป Author

Ayush (Hardik Soni)

Software Developer | Java | Full-Stack & Mobile Application Development


๐Ÿ“„ License

This project is available for educational and learning purposes. Please check the repository's license information before reusing or distributing the code.


Built with Java and MySQL | Learning by Building ๐Ÿš€

About

A Java-based Online Voting System using JDBC and MySQL, featuring voter registration, authentication, candidate management, secure vote submission, duplicate-voting prevention, and election result tracking.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages