Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Spring MVC with MySQL and Junit - Finding Employees Based on Location
Next article icon

Spring MVC with MySQL and Junit - Finding Employees Based on Location

Last Updated : 01 May, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

In real-world scenarios, organizations are existing in different localities. Employees are available in many locations. Sometimes they work in different 2 locations i.e. for a few days, they work on location 1 and for a few other days, they work on location 2. Let's simulate this scenario via MySQL queries and prepare a Spring MVC application that interacts with MySQL and get the required details. And also let us see JUNIT test cases as well.

Required MySQL Queries:

DROP DATABASE IF EXISTS test;  CREATE DATABASE test;  USE test;  DROP TABLE test.employeesdetails;  CREATE TABLE `employeesdetails` (   `id` int(6) unsigned NOT NULL,   `Name` varchar(50) DEFAULT NULL,   `AvailableDays` varchar(200) DEFAULT NULL,   `location` varchar(50) DEFAULT NULL,   `qualification` varchar(20) DEFAULT NULL,   `experience` int(11) DEFAULT NULL,   `gender` varchar(10) DEFAULT NULL,   PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;  INSERT INTO `test`.`employeesdetails` (`id`,`Name`,`AvailableDays`,`location`,`qualification`, `experience`,`gender`) VALUES (1,'EmployeeA','Monday,Tuesday,Friday','Location1','BE',5,'Female');  INSERT INTO `test`.`employeesdetails` (`id`,`Name`,`AvailableDays`,`location`,`qualification`, `experience`,`gender`) VALUES (2,'EmployeeB','Monday,Wednesday,Friday','Location1','MCA',3,'Female');  INSERT INTO `test`.`employeesdetails` (`id`,`Name`,`AvailableDays`,`location`,`qualification`, `experience`,`gender`) VALUES (3,'EmployeeC', 'Wednesday,Thursday','Location2','BE',5,'Female');  INSERT INTO `test`.`employeesdetails` (`id`,`Name`,`AvailableDays`,`location`,`qualification`, `experience`,`gender`) VALUES (4,'Employees','Saturday,Sunday','Location2','MBA',4,'Male');  INSERT INTO `test`.`employeesdetails` (`id`,`Name`,`AvailableDays`,`location`,`qualification`, `experience`,`gender`) VALUES (5,'EmployeeE','Tuesday,Thursday','Location2','MCA',3,'Female');  INSERT INTO `test`.`employeesdetails` (`id`,`Name`,`AvailableDays`,`location`,`qualification`, `experience`,`gender`) VALUES (6,'EmployeeA','Wednesday,Thursday','Location2','BE',5,'Female');  SELECT * FROM test.employeesdetails;

Output of test.employeesdetails:

 

With this setup, let us start the Spring MVC project that interacts with MySQL and produce the details upon our queries

Implementation

Project Structure:

Project Structure
 

This is a Maven-driven project. Let's start with 

pom.xml

XML
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0                               http://maven.apache.org/maven-v4_0_0.xsd">    <modelVersion>4.0.0</modelVersion>    <groupId>com.employees</groupId>    <artifactId>SpringMVCFindEmployee</artifactId>    <packaging>war</packaging>    <version>0.0.1-SNAPSHOT</version>    <name>SpringMVCFindEmployee Maven Webapp</name>    <url>http://maven.apache.org</url>    <properties>       <failOnMissingWebXml>false</failOnMissingWebXml>       <spring-version>5.1.0.RELEASE</spring-version>    </properties>    <dependencies>       <dependency>          <groupId>junit</groupId>          <artifactId>junit</artifactId>          <version>4.12</version>          <scope>test</scope>       </dependency>       <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->       <dependency>          <groupId>org.mockito</groupId>          <artifactId>mockito-all</artifactId>          <version>1.9.5</version>          <scope>test</scope>       </dependency>       <dependency>          <groupId>org.springframework</groupId>          <artifactId>spring-webmvc</artifactId>          <version>${spring-version}</version>       </dependency>       <dependency>          <groupId>org.springframework</groupId>          <artifactId>spring-context</artifactId>          <version>${spring-version}</version>       </dependency>       <dependency>          <groupId>org.springframework</groupId>          <artifactId>spring-test</artifactId>          <version>${spring-version}</version>       </dependency>       <!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper -->       <dependency>          <groupId>org.apache.tomcat</groupId>          <artifactId>tomcat-jasper</artifactId>          <version>9.0.12</version>       </dependency>       <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->       <dependency>          <groupId>javax.servlet</groupId>          <artifactId>javax.servlet-api</artifactId>          <version>3.1.0</version>          <scope>provided</scope>       </dependency>       <!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->       <dependency>          <groupId>javax.servlet</groupId>          <artifactId>jstl</artifactId>          <version>1.2</version>       </dependency>       <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->       <dependency>          <groupId>mysql</groupId>          <artifactId>mysql-connector-java</artifactId>          <version>8.0.11</version>       </dependency>       <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->       <dependency>          <groupId>org.springframework</groupId>          <artifactId>spring-jdbc</artifactId>          <version>${spring-version}</version>       </dependency>    </dependencies>    <build>       <finalName>SpringMVCFindEmployee</finalName>       <sourceDirectory>src/main/java</sourceDirectory>       <plugins>          <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-compiler-plugin</artifactId>             <version>3.5.1</version>             <configuration>                <source>1.8</source>                <target>1.8</target>             </configuration>          </plugin>          <!-- This should be added to overcome Could not initialize                class org.apache.maven.plugin.war.util.WebappStructureSerializer -->          <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-war-plugin</artifactId>             <version>3.3.2</version>          </plugin>       </plugins>    </build> </project> 

Let's see some important java files.

Bean class

Employee.java

Java
public class Employee {     // All instance variables should       // match with the columns present       // in MySQL test.employeedetails table     private int id;     private String name;     private float salary;     private String availableDays;     private String location;     private String qualification;     private int experience;     private String gender;     public String getLocation() {         return location;     }      public void setLocation(String location) {         this.location = location;     }      public String getQualification() {         return qualification;     }      public void setQualification(String qualification) {         this.qualification = qualification;     }      public int getExperience() {         return experience;     }      public void setExperience(int experience) {         this.experience = experience;     }      public String getGender() {         return gender;     }      public void setGender(String gender) {         this.gender = gender;     }      public int getId() {         return id;     }      public void setId(int id) {         this.id = id;     }      public String getName() {         return name;     }      public void setName(String name) {         this.name = name;     }      public float getSalary() {         return salary;     }      public void setSalary(float salary) {         this.salary = salary;     }      public String getAvailableDays() {         return availableDays;     }      public void setAvailableDays(String availableDays) {         this.availableDays = availableDays;     }  } 

EmployeeController.java

Java
import com.employees.beans.Employee; import com.employees.dao.EmployeeDao; import java.sql.SQLException; import java.util.StringTokenizer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.servlet.ModelAndView;  @Controller @SessionAttributes("employee") public class EmployeeController {     @Autowired     EmployeeDao dao;       @Autowired public EmployeeController(EmployeeDao dao)     {         this.dao = dao;     }      @ModelAttribute("employee")     public Employee getEmployee()     {         return new Employee();     }      // for searchform     @RequestMapping("/employeesearchform")     public String searchform(Model m)     {         m.addAttribute("command", new Employee());         return "employeesearchform";     }      // It provides search of employees in model object     @RequestMapping(value = "/searchEmployee",                     method = RequestMethod.POST)     public ModelAndView     searchEmployee(@ModelAttribute("employee")                    Employee employee)     {          ModelAndView mav = null;         Employee employee1;         try {             employee1 = dao.getEmployeesByNameAndLocation(                 employee.getName(), employee.getLocation());             mav = new ModelAndView("welcome");             if (null != employee1) {                 System.out.println(                     employee1.getId() + "..."                     + employee1.getName() + ".."                     + employee1.getAvailableDays()                     + "..chosen location.."                     + employee.getLocation());                 StringTokenizer st = new StringTokenizer(                     employee1.getAvailableDays(), ",");                 boolean isAvailable = false;                 while (st.hasMoreTokens()) {                     // System.out.println(st.nextToken());                     // if                     // (st.nextToken().equalsIgnoreCase(employee.getAvailableDays()))                     // {                     isAvailable = true;                     break;                     //}                 }                  mav.addObject("firstname",                               employee1.getName());                 if (isAvailable) {                     mav.addObject("availability",                                   "Available on");                 }                 else {                     mav.addObject("availability",                                   "Not Available on");                 }                 mav.addObject("day",                               employee1.getAvailableDays());                 mav.addObject("location",                               employee.getLocation());             }             else {                 mav.addObject("firstname",                               employee.getName());                 mav.addObject("availability",                               "Not Available ");                 mav.addObject("location",                               employee.getLocation());             }         }         catch (SQLException e) {             // TODO Auto-generated catch block             e.printStackTrace();         }          return mav;     } } 

EmployeeDao.java

Java
import com.employees.beans.Employee; import java.sql.SQLException; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate;  public class EmployeeDao {     // We can straight away write SQL queries related to     // MySQL as we are using JdbcTemplate     JdbcTemplate template;      public void setTemplate(JdbcTemplate template)     {         this.template = template;     }      public Employee     getEmployeesByNameAndLocation(String employeeName,                                   String locationName)         throws SQLException     {         String sql             = "select * from employeesdetails where name=? and location = ?";         return template.queryForObject(             sql,             new Object[] { employeeName, locationName },             new BeanPropertyRowMapper<Employee>(                 Employee.class));     }      public Employee     getEmployeesByGender(String gender,                          String availabledays)         throws SQLException     {         String sql             = "select * from employeesdetails where gender=? and availabledays = ?";         return template.queryForObject(             sql, new Object[] { gender, availabledays },             new BeanPropertyRowMapper<Employee>(                 Employee.class));     }      public Employee     getEmployeesByQualification(String qualification,                                 String availabledays)         throws SQLException     {         String sql             = "select * from employeesdetails where qualification=? and availabledays = ?";         return template.queryForObject(             sql,             new Object[] { qualification, availabledays },             new BeanPropertyRowMapper<Employee>(                 Employee.class));     }      public Employee     getEmployeesByExperience(int experienceInYears)         throws SQLException     {         String sql             = "select * from employeesdetails where experience=?";         return template.queryForObject(             sql, new Object[] { experienceInYears },             new BeanPropertyRowMapper<Employee>(                 Employee.class));     } } 

We need to have an important file called spring-servlet.xml. This will have the MySQL connectivity information

XML
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"         xmlns:context="http://www.springframework.org/schema/context"         xmlns:mvc="http://www.springframework.org/schema/mvc"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="                     http://www.springframework.org/schema/beans                           http://www.springframework.org/schema/beans/spring-beans.xsd                   http://www.springframework.org/schema/context                             http://www.springframework.org/schema/context/spring-context.xsd                    http://www.springframework.org/schema/mvc                              http://www.springframework.org/schema/mvc/spring-mvc.xsd">    <context:component-scan base-package="com.employees.controllers" />    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">       <property name="prefix" value="/WEB-INF/jsp/" />       <property name="suffix" value=".jsp" />    </bean>    <bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">       <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" />       <!-- As we are using test database, it is given as test here            Modify it according to your database name useSSL=false            is required to overcome SSL errors -->       <property name="url" value="jdbc:mysql://localhost:3306/test?useSSL=false" />       <property name="username" value="root" />       <property name="password" value="*****" />       <!--Specify correct password here -->    </bean>    <bean id="jt" class="org.springframework.jdbc.core.JdbcTemplate">       <property name="dataSource" ref="ds" />    </bean>    <bean id="dao" class="com.employees.dao.EmployeeDao">       <property name="template" ref="jt" />    </bean> </beans> 

Ok, now let us use JSP pages to search the employees by using the Spring MVC project and the available data present in the MySQL

index.jsp

Java
// Beautify the code if required, // This will provide a hyperlink and // it will go to the employeesearchform.jsp <center> <a href="employeesearchform">Search Employees By Location</a></center> 

employeesearchform.jsp

HTML
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>   <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>   <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html>    <head>       <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">       <title>Search Employees</title>    </head>    <body>       <h1>Search Employees</h1>       <form:form  method="post" action="/SpringMVCFindEmployee/searchEmployee"  >          <table >             <tr>                <td>Employee Name : </td>                <td>                   <form:input path="name"/>                </td>             </tr>             <tr>                <td>Choose a Location : </td>                <td>                   <form:select path="location">                      <form:option value="Location1" label="Location1"/>                      <form:option value="Location2" label="Location2"/>                   </form:select>                </td>             </tr>             <tr>                <td> </td>                <td><input type="submit" value="Search" /></td>             </tr>          </table>       </form:form>    </body> </html> 

Output:

Spring MVC with MySQL and Junit Output
 

After entering details, the output is shown via

welcome.jsp

HTML
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"                          "http://www.w3.org/TR/html4/loose.dtd"> <html>    <head>       <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">       <title>Welcome</title>    </head>    <body>       <table>          <tr>             <td> Employee Name :</td>             <td>${firstname}</td>          </tr>          <tr>             <td> Availability :</td>             <td>${availability} </td>             <td>${day}</td>             <td> at ${location}</td>          </tr>          <tr>          </tr>          <tr>          </tr>          <tr>             <td><a href="employeesearchform">Search Again</a>             </td>          </tr>       </table>    </body> </html> 
welcome.jsp output
 

We can check the same via our test cases as well

EmployeeControllerTest.java

Java
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;  import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext;  import com.employees.beans.Employee; import com.employees.controllers.EmployeeController; import com.employees.dao.EmployeeDao;  @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring-servlet.xml" }) @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration public class EmployeeControllerTest {        @InjectMocks     private EmployeeController employeeController;       private MockMvc mockMvc;      @Autowired     private EmployeeDao dao;          @Autowired     WebApplicationContext webApplicationContext;           @Before     public void setup() {         MockitoAnnotations.initMocks(this);         this.mockMvc = MockMvcBuilders.standaloneSetup(employeeController).build();              }       @Test     // 404 error thrown when coming from invalid resources     public void testCreateSearchEmployeesPageFormInvalidUser() throws Exception {         this.mockMvc.perform(get("/"))         .andExpect(status().isNotFound());     }                   @Test        // positive testcase       public void testSearchEmployeesByNameAndCheckAvailability() throws Exception {            Employee employee = new Employee();            employee.setName("EmployeeA");            employee.setLocation("Location1");            employee = dao.getEmployeesByNameAndLocation(employee.getName(),employee.getLocation());           Assert.assertEquals(1, employee.getId());           Assert.assertEquals("Monday,Tuesday,Friday", employee.getAvailableDays());       }          @Test        // Negative testcase       public void testSearchEmployeesByNameAndCheckAvailabilityWithNotEqualsValues() throws Exception {            Employee employee = new Employee();            employee.setName("EmployeeA");            employee.setLocation("Location2");            employee = dao.getEmployeesByNameAndLocation(employee.getName(),employee.getLocation());           Assert.assertNotEquals(10, employee.getId());           Assert.assertNotEquals("Tuesday,Thursday", employee.getAvailableDays());       }        @Test        //Negative  testcase i.e. Given gender as Male and available days as Saturday       public void testSearchEmployeesByGender() throws Exception {            Employee employee = new Employee();            employee.setGender("Male");            employee.setAvailableDays("Saturday,Sunday");            employee = dao.getEmployeesByGender(employee.getGender(),employee.getAvailableDays());           Assert.assertEquals(4, employee.getId());           Assert.assertNotEquals("EmployeeB", employee.getName());           Assert.assertNotEquals(1, employee.getExperience());       }              @Test        // Negative  testcase i.e. Given gender as Male and available days as Saturday       public void testSearchEmployeesByGenderWithCorrectResults() throws Exception {            Employee employee = new Employee();            employee.setGender("Male");            employee.setAvailableDays("Saturday,Sunday");            employee = dao.getEmployeesByGender(employee.getGender(),employee.getAvailableDays());           Assert.assertEquals(4, employee.getId());           Assert.assertNotEquals("EmployeeB", employee.getName());           Assert.assertNotEquals(1, employee.getExperience());       }              @Test        // Negative  testcase i.e. giving experience as 4 years and checking       // as the name of the doctor to be DoctorE instead of DoctorD        public void testSearchEmployeesByExperience() throws Exception {            Employee employee = new Employee();            employee.setExperience(4);            employee = dao.getEmployeesByExperience(employee.getExperience());           Assert.assertEquals(4, employee.getId());           Assert.assertNotEquals("EmployeeF", employee.getName());       }              @Test        public void testSearchEmployeesByQualification() throws Exception {            Employee employee = new Employee();            employee.setQualification("MBA");            employee.setAvailableDays("Saturday,Sunday");            employee = dao.getEmployeesByQualification(employee.getQualification(),employee.getAvailableDays());           Assert.assertEquals(4, employee.getId());           Assert.assertEquals("EmployeeD", employee.getName());           Assert.assertNotEquals(15, employee.getExperience());       }           } 

On executing the test cases, we can see the below output

test cases output
 

One can simulate this kind of scenario, and prepare a spring MVC project along with JUNIT test cases.


Next Article
Spring MVC with MySQL and Junit - Finding Employees Based on Location

P

priyarajtt
Improve
Article Tags :
  • Java
  • Project
  • mysql
  • Java-Spring
  • Java-Spring-MVC
  • JUnit
Practice Tags :
  • Java

Similar Reads

    How to Make Delete Request in Spring?
    Java language is one of the most popular languages among all programming languages. There are several advantages of using the java programming language, whether for security purposes or building large distribution projects. One of the advantages of using JAVA is that Java tries to connect every conc
    4 min read
    How to Make get() Method Request in Java Spring?
    Java language is one of the most popular languages among all programming languages. There are several advantages of using the java programming language, whether for security purposes or building large distribution projects. One of the advantages of using JAVA is that Java tries to connect every conc
    3 min read
    Spring @RequestMapping Annotation with Example
    The @RequestMapping annotation in Spring MVC is one of the most important annotations used to map HTTP requests to handler methods of MVC and REST controllers. In Spring MVC applications, the DispatcherServlet (Front Controller) is responsible for routing incoming HTTP requests to the handler method
    4 min read
    How to Capture Data using @RequestParam Annotation in Spring?
    The @RequestParam annotation enables Spring to capture input data that may be passed as a query, form data, or any arbitrary custom data. It is used to bind a web request parameter to a method parameter. Here, we are going to understand these two above lines, and we will see how we can capture data
    6 min read
    Spring @ResponseBody Annotation with Example
    Spring Annotations allow us to configure dependencies and implement dependency injection through java programs. Those are used to provide supplemental information about a program. It does not have a direct effect on the operation of the code they annotate. It does not change the action of the compil
    4 min read
    Spring MVC Project - Retrieving Population, Area and Region Details using Rest API
    REST API is more popular nowadays as we can able to get a variety of information like Population, Area, region, sub-region, etc., One such REST API that we are going to see here is https://restcountries.com/v3.1/capital/<any capital of a country> Example: https://restcountries.com/v3.1/capital
    4 min read
    Spring MVC - Last 24 Hour Cryptocurrency Data using REST API
    Cryptocurrencies are a hot topic now and in the future; they may also be a payment source. Hence a lot of research is getting done. Many REST APIs are available to provide data in JSON format. We are going to see one such REST API as https://api.wazirx.com/sapi/v1/ticker/24hr?symbol=<Need to prov
    5 min read
    Spring MVC - Sample Project For Finding Doctors Online with MySQL
    Spring MVC Framework follows the Model-View-Controller design pattern. It is used to develop web applications. It works around DispatcherServlet. DispatcherServlet handles all the HTTP requests and responses. With MySQL as the backend, we can store all doctor details and by using Spring MVC function
    5 min read
    Spring MVC JSTL Configuration
    JavaServer Pages Tag Library (JSTL) is a set of tags that can be used for implementing some common operations such as looping, conditional formatting, and others. Here we will be discussing how to use the Maven build tool to add JSTL support to a Spring MVC application. also, you'll learn how to act
    1 min read
    Spring MVC with MySQL - Sample Project For Calculating Electricity Bill
    Let us see a sample electricity bill calculation project by using Spring MVC + MySQL connectivity + JDBCTemplate. Additionally, let us test the same by using MockMvc + JUnit. MySQL Queries: DROP DATABASE IF EXISTS test; CREATE DATABASE test; USE test; DROP TABLE test.personsdetails; CREATE TABLE per
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences