VOOZH about

URL: https://www.geeksforgeeks.org/java/spring-mvc-sample-project-for-finding-doctors-online-with-mysql/

โ‡ฑ Spring MVC - Sample Project For Finding Doctors Online with MySQL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Spring MVC - Sample Project For Finding Doctors Online with MySQL

Last Updated : 7 Oct, 2025

Spring MVC is a web framework based on the Modelโ€“Viewโ€“Controller (MVC) architectural pattern. It helps in building dynamic web applications by separating application logic, presentation and data access layers.

In this project, weโ€™ll develop a Spring MVC application that interacts with MySQL to find doctor details online. It uses Spring JDBC for database interaction and follows a layered structure for maintainability.

MySQL Setup

Create and populate the database before running the project.

DROP DATABASE IF EXISTS geeksforgeeks;

CREATE DATABASE geeksforgeeks;

USE geeksforgeeks;


CREATE TABLE DoctorsDetails (

id INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,

doctorName VARCHAR(50) NOT NULL,

doctorRegistrationNumber VARCHAR(10) NOT NULL,

qualification VARCHAR(30) NOT NULL,

gender VARCHAR(10),

PRIMARY KEY (id)

);


INSERT INTO DoctorsDetails (doctorName, doctorRegistrationNumber, qualification, gender) VALUES

('doctorA', '123-456', 'MDDCH', 'Female'),

('doctorB', '111-222', 'MSNeuro', 'Male'),

('doctorC', '222-444', 'MDGynae', 'Female'),

('doctorD', '199-998', 'MSNephro', 'Male'),

('doctorE', '444-666', 'MDCardio', 'Female');


SELECT * FROM DoctorsDetails;

Database Output

๐Ÿ‘ dbdata
DB Output

Project Structure:

๐Ÿ‘ Project Structure
Project Structure

This is a Maven Web Application.

pom.xml

Model Class โ€“ Doctor.java

Controller Layer โ€“ DoctorController.java

DAO Layer โ€“ DoctorDao.java

Configuration โ€“ spring-servlet.xml

Update database credentials (username, password) in spring-servlet.xml.

View Layer

indexPage.jsp

We would be getting a page like below

๐Ÿ‘ Image
Home View Page

On click of the "Find Doctors Online" link, we can get the below page

doctorsearchform.jsp

welcome.jsp

Ensure Tomcat is configured and running before deployment.

Output:

Open the application home page, click Find Doctors Online.

๐Ÿ‘ doctorsearchform
Welcome screen

Enter a Doctor Name or Registration Number.

๐Ÿ‘ registrationnumber
Enter doctor name or registration no.

On submission, details will be fetched from MySQL and displayed on welcome.jsp.

๐Ÿ‘ file
Doctor details

Key Points

  • DispatcherServlet handles all HTTP requests and responses.
  • JdbcTemplate simplifies SQL operations without manual connection handling.
  • ModelAttribute binds form data to the model.
  • InternalResourceViewResolver maps logical view names to JSP files.
  • Maven manages dependencies and builds the WAR for deployment on Tomcat.
Comment