100% found this document useful (1 vote)
306 views

JSP Servlet JDBC MySQL CRUD Example

This document describes building a simple user management web application using JSP, Servlets, JDBC, and MySQL (CRUD operations). The application allows users to be created, updated, deleted, retrieved, and listed. It uses technologies like Eclipse, Tomcat, MySQL, JSTL. The development process involves setting up the project structure, adding dependencies, creating JavaBeans, DAO classes, servlets, JSP pages for listing, creating, and editing users, and deploying the application.

Uploaded by

darwinvargas2011
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
306 views

JSP Servlet JDBC MySQL CRUD Example

This document describes building a simple user management web application using JSP, Servlets, JDBC, and MySQL (CRUD operations). The application allows users to be created, updated, deleted, retrieved, and listed. It uses technologies like Eclipse, Tomcat, MySQL, JSTL. The development process involves setting up the project structure, adding dependencies, creating JavaBeans, DAO classes, servlets, JSP pages for listing, creating, and editing users, and deploying the application.

Uploaded by

darwinvargas2011
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

JSP SERVLET JDBC MYSQL CRUD

EXAMPLE

D Vargas
JSP SERVLET JDBC
MYSQL CRUD EXAMPLE
In this JSP Project, we are building a simple User Management web application that manages
a collection of users with the basic feature: list, insert, update, delete (or CURD operations -
Create, Update, Read and Delete).
JSP Servlet
We will develop below simple JDBC MySQL
basic features in our User CRUD Example
Management web application:

• Create a User
• Update a User
• Delete a User
• Retrieve a User
• List of all Users
The application
looks something like
this:
Tools and technologies used

IDE -
Apache Tomcat -
JSP - 2.2 + STS/Eclipse JDK - 1.8 or later
8.5
Neon.3

MySQL - mysql-
JSTL - 1.2.1 Servlet API - 2.5 connector-java-
8.0.13.jar
Development Steps

Create an Eclipse
MySQL Database
Dynamic Web Add Dependencies Project Structure
Setup
Project

Creating User
Create a JavaBean Create a Create a
Listing JSP Page -
- User.java UserDAO.java UserServlet.java
user-list.jsp

Create a User Deploying and


Creating Error JSP
Form JSP Page - Testing the
page
user-form.jsp Application Demo
Class Diagram
1. Create an Eclipse Dynamic Web Project

To create a new dynamic Web project in Eclipse:


1. On the main menu select File > New >
Project....
2. In the upcoming wizard choose Web >
Dynamic Web Project.
3. Click Next.
4. Enter project name as "jsp-servlet-jdbc-
mysql-example";
5. Make sure that the target runtime is set to
Apache Tomcat with the currently supported
version. 
2. Add
Add the latest release of Dependencies
below jar files to
the lib folder.
• jsp-api.2.3.1.jar
• servlet-api.2.3.jar
• mysql-connector-java-8.0.13.jar
• jstl-1.2.jar
3. Project
Structure

Standard project structure for


your reference
4. MySQL
Database Setup

Let's create a database named


"demo" in MySQL. Now, create
a users table using below DDL
script:
5. Create a
JavaBean -
User.java
Let's create a User java class to
model a user entity in the
database with the following
code
. Create a
UserDAO.java
Let's create a UserDAO class
which is a Data Access Layer
(DAO) class that provides
CRUD (Create, Read, Update,
Delete) operations for the
table users in a database.
Here’s the full source code of
the UserDAO:
. Create a
UserDAO.java
. Create a
UserDAO.java
. Create a
UserDAO.java
7. Create a
UserServlet.java

Now, let's
create UserServlet that acts as a
page controller to handle all
requests from the client. Let’s
look at the code first
7. Create a
UserServlet.java
7. Create a
UserServlet.java
8. Creating User
Listing JSP Page -
user-list.jsp

Next, create a JSP page for


displaying all users from the
database. Let's create a list-
user.jsp page under
the WebCon
tent directory in the project
with the following code:
8. Creating User
Listing JSP Page
- user-list.jsp
Once you will deploy above
JSP page in tomcat and open in
the browser looks something
like this:
9. Create a User
Form JSP Page -
user-form.jsp

Next, we create a JSP page for


creating a new User called user-
form.jsp. Here’s its full source
code:
9. Create a User
Form JSP Page -
user-form.jsp
Once you will deploy above
JSP page in tomcat and open in
the browser looks something
like this:
The above page acts for both functionalities to create a new User and Edit the same user. The edit
page looks like:
10. Creating Error JSP page

◦ Here’s the code of the Error.jsp page which simply shows the exception message:
11. Deploying and
Testing the
Application

It's time to see a demo of the above User Management web


application. Deploy this web application in tomcat server. 

Type the following URL in your web browser to access


the User Management application: 
http://localhost:8080/jsp-servlet-jdbc-mysql-crud-example/
Create a new
User
Edit a User
List of all Users
Title Lorem Ipsum

LOREM IPSUM DOLOR SIT AMET, NUNC VIVERRA IMPERDIET PELLENTESQUE HABITANT
CONSECTETUER ADIPISCING ENIM. FUSCE EST. VIVAMUS A MORBI TRISTIQUE SENECTUS ET
ELIT. TELLUS. NETUS.

You might also like