CRUD JDBC Project in Java with MySql Source Code

CRUD JDBC Project in Java is a good and basic project for beginners this project will help you to understand the basic concepts of JDBC operation. Here we have covered more than 11 JDBC operations.

Database connection with java is one of the essential features of java, In java to connect with the database we use java database connectivity(JDBC) programs.

JDBC is an Application Program Interface(API) that is used to interact with database and java programs in database independent way.

So JDBC (complete form Java Database Connectivity) code to interact with MySQL, oracle database, and other databases.

Here we used JDBC with MySQL to connect it we need a MySQL JDBC driver to connect MySQL with java.

Here we will see a java JDBC project to perform all basic operations involved in Database interaction.

Using Employee details program in java using JDBC operations.

Setting Up CRUD JDBC Project in Java

JDBC project setup is in two part

  • create a database
  • Write Java, JDBC codes

Creating database

  • Create a database username with a password.
  • given all privileges to the user.
  • designed database and table for employees.

Above all details are set in the following script.

Run this script before running the java JDBC program

CRUD JDBC Project in Java Creating Classes

Writing Java Jdbc Code

  • Create Java Bean
  • Creating Main class (Execution starts from here)
  • Create Action class
  • Create DAO class

Java Bean

A Java Bean is a simple java class, that holds all properties, getter-setter methods, and constructors of the class.

Java Bean for Employee class is given below

Create Main Class

Below is the main class for running all java JDBC examples

Here you find various examples like inserting in the table, updating the table, deleting a record from the MySQL table, and selecting a specific or all record from the table.

To run the below code see all actions and operations in the below table

Sr NoOperation and codeAction
1ADD (1)Add Employee records in database should be initialize only once. First time after creating database
2UPDATE (2)Update a record in table, based on primary key id
3DELETE (3)Insert a new record to table and delete it from database
4FETCH BY ID (4)Fetch a record from table based on id
5FETCH BY EMAIL (5)Fetch a record from table based on email
6FETCH BY MOBILE NO (6)Fetch a record from table based on mobile number
7SEARCH BY NAME (7)Fetch records from table based on Name
8FETCH BY CITY (8)Fetch records from table based on city name
9FETCH BY SALARY RANGE (9)Fetch records from table based on Salary Range
10FETCH BY DOB (10)Fetch records from table based on date of birth
11FETCH BY DOJ RANGE (11)Fetch records from table based on Date of Joining Range
12FETCH ALL (12)Fetch all records from table
13EXIT (0)EXIT FROM ALL OPERATION

Create Action Class

The above class will call the method of the below action class

Create DAO class

The above action class will call to below DAO class method

Here All JDBC Prepared statement are used to interact with mysql

Various JDBC operations used here are

  • Insert
  • Update
  • Delete
  • FetchById
  • FetchByEmailId
  • FetchByMobileNo
  • SearchByName
  • FetchByCity
  • FetchBySalaryRange
  • FetchByDob
  • FetchByDojRange
  • FetchAll

Let’s see one by one each method

JDBC Insert Employee Details in MySql

JDBC Update Employee Details in MySQL

JDBC Delete Employee Details from MySQL

JDBC Fetch Employee Details based on Id

JDBC Fetch Employee Details based on Email Id

JDBC Fetch Employee Details based on Mobile Number

JDBC Search Employee Details based on Name

JDBC Fetch Employee Details based on City Name

JDBC Fetch Employee Details based on Salary Range

JDBC Fetch Employee Details based on Date of Birth (DOB)

JDBC Fetch Employee Details based on Date of Joining Range (DOJ)

JDBC Fetch Employee Details Order by Id DESC

All Complete codes for JDBC Operations

Download this Java Project with source code for GitHub

Employee Management System Project JSP Servlet