title: Error creating bean with name 'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping'
body: <p>I created a web application using Spring 4.3.1.Two days ago the application was working perfectly fine but now I am getting following errors.I am unable to make out actual cause of problem.</p>
  
  <pre><code>    javax.servlet.ServletException: Servlet.init() for servlet spring-dispatcher        threw exception
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Unknown Source)
  root cause
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.OnlineStore.DAO.UserDetailsDAOImpl] for bean with name 'userDetailsImpl' defined in ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.OnlineStore.DAO.UserDetailsDAOImpl
  Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.OnlineStore.DAO.UserDetailsDAOImpl] for bean with name 'userDetailsImpl' defined in ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.OnlineStore.DAO.UserDetailsDAOImpl
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      javax.servlet.GenericServlet.init(GenericServlet.java:158)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Unknown Source)
  root cause
  
  org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.OnlineStore.DAO.UserDetailsDAOImpl] for bean with name 'userDetailsImpl' defined in ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.OnlineStore.DAO.UserDetailsDAOImpl
      org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1357)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:628)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:597)
      org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1450)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:446)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:424)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:410)
      org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1172)
      org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.detectHandlers(AbstractDetectingUrlHandlerMapping.java:75)
      org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.initApplicationContext(AbstractDetectingUrlHandlerMapping.java:58)
      org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:120)
      org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:76)
      org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:74)
      org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:121)
      org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:97)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      javax.servlet.GenericServlet.init(GenericServlet.java:158)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Unknown Source)
  root cause
  
  java.lang.ClassNotFoundException: com.OnlineStore.DAO.UserDetailsDAOImpl
      org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1891)
      org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1734)
      org.springframework.util.ClassUtils.forName(ClassUtils.java:250)
      org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:394)
      org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1402)
      org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1349)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:628)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:597)
      org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1450)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:446)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:424)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:410)
      org.springframework.context.support.AbstractApplicationContext.getBeanNamesForType(AbstractApplicationContext.java:1172)
      org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.detectHandlers(AbstractDetectingUrlHandlerMapping.java:75)
      org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.initApplicationContext(AbstractDetectingUrlHandlerMapping.java:58)
      org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:120)
      org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:76)
      org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:74)
      org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:121)
      org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:97)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:408)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      javax.servlet.GenericServlet.init(GenericServlet.java:158)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>Spring-dispatcher-servlet.xml</p>
  
  <pre><code>&lt;beans  xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context" 
  xmlns:mvc="http://www.springframework.org/schema/mvc" 
  xmlns:flow="http://www.springframework.org/schema/webflow-config"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-2.5.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
  http://www.springframework.org/schema/webflow-config
  http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd"&gt;
  
  &lt;!--
  &lt;bean id = "HandlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/&gt;
  
   &lt;bean name ="/welcome.html" class="retailbeans.HomeClass"&gt;
  &lt;/bean&gt; --&gt;
  
  &lt;context:component-scan base-package="com.OnlineStore.Control"/&gt;
  &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
  &lt;property name="prefix"&gt;&lt;value&gt;/WEB-INF/Pages/&lt;/value&gt;&lt;/property&gt;
  &lt;property name="suffix"&gt;&lt;value&gt;.jsp&lt;/value&gt;&lt;/property&gt;
  
  &lt;/bean&gt;
  &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
  &lt;mvc:annotation-driven /&gt;
  
  
  &lt;!-- Initialization for data source --&gt;
     &lt;bean id="storedatasource" 
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
     &lt;property name="url" value="jdbc:mysql://localhost:3306/MYSQL" /&gt;
     &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
     &lt;property name="username" value="abhi" /&gt;
     &lt;property name="password" value="abhi123" /&gt;
     &lt;/bean&gt;
  
  &lt;!--  Dao class configuration in spring --&gt;
   &lt;bean id="userDetailsImpl" class="com.OnlineStore.DAO.UserDetailsDAOImpl"&gt;
      &lt;property name="dataSource" ref="storedatasource"/&gt;
   &lt;/bean&gt;
  
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>UserDetailsDAOImpl.java</p>
  
  <pre><code>package com.OnlineStore.DAO;
  
  
  
  
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.StringTokenizer;
  
  import javax.sql.DataSource;
  
  import org.apache.commons.lang.StringUtils;
  
  import com.OnlineStore.DAO.IUserDetailsDAO;
  import com.OnlineStore.Entity.CategoryEntity;
  import com.OnlineStore.Entity.ProductDetailEntity;
  import com.OnlineStore.Entity.UserDetailEntity;
  import com.OnlineStore.Entity.UserDetailsEntity;
  
  
  public class UserDetailsDAOImpl implements IUserDetailsDAO{
      private DataSource dataSource;
      private List&lt;ProductDetailEntity&gt; productListMen=new ArrayList&lt;ProductDetailEntity&gt;();
      private List&lt;ProductDetailEntity&gt; productListWomen=new ArrayList&lt;ProductDetailEntity&gt;();
      private List&lt;ProductDetailEntity&gt; productListChild=new ArrayList&lt;ProductDetailEntity&gt;();
      private List&lt;ProductDetailEntity&gt; productListMenDisc=new ArrayList&lt;ProductDetailEntity&gt;();
      private List&lt;ProductDetailEntity&gt; productListWomenDisc=new ArrayList&lt;ProductDetailEntity&gt;();
      private List&lt;ProductDetailEntity&gt; productListChildDisc=new ArrayList&lt;ProductDetailEntity&gt;();
      private boolean flagPopulation=false;
  
       public void setDataSource(DataSource dataSource) {
            this.dataSource = dataSource;
         }
  
  
  
  
  
      @Override
      public UserDetailEntity validateUser(UserDetailEntity user) {
  String sql = "SELECT * FROM userdetails where enPassword =? and  email =?";
  
          Connection conn = null;
  
          try {
              conn = dataSource.getConnection();
              PreparedStatement ps = conn.prepareStatement(sql);
              ps.setString(1, user.getPassword());
              ps.setString(2, user.getEmail());
              ResultSet result=ps.executeQuery();
              UserDetailEntity userdetails=new UserDetailEntity();
              if(result != null &amp;&amp; result.next()){
                  userdetails.setFirstname(result.getString("firstName"));
                  userdetails.setLastname(result.getString("lastName"));
                  userdetails.setEmail(result.getString("email"));
                  userdetails.setPhone(result.getString("mobile"));
                  userdetails.setFirstname(result.getString("firstName"));
                  }
              ps.close();
              return userdetails;
  
          } catch (SQLException e) {
              throw new RuntimeException(e);
  
          } finally {
              if (conn != null) {
                  try {
                      conn.close();
                  } catch (SQLException e) {}
              }
          }
      }
      @Override
      public void addUser(UserDetailEntity user) {
          String sql = "INSERT INTO userdetails " +
                  "(enPassword, firstName , lastName, email , mobile, gender) VALUES (?, ?, ?, ? ,? ,? )";
  
          Connection conn = null;
  
          try {
              conn = dataSource.getConnection();
              PreparedStatement ps = conn.prepareStatement(sql);
              ps.setString(1, user.getPassword());
              ps.setString(2, user.getFirstname());
              ps.setString(3, user.getLastname());
              ps.setString(4, user.getEmail());
              ps.setString(5, user.getPhone());
              ps.setString(6,user.getGender());
  
              ps.executeUpdate();
              ps.close();
  
          } catch (SQLException e) {
              throw new RuntimeException(e);
  
          } finally {
              if (conn != null) {
                  try {
                      conn.close();
                  } catch (SQLException e) {}
              }
          }
  
      }
  
      @Override
      public List&lt;ProductDetailEntity&gt; productDetailsList() {
  
          String sql = "select * from ProductDetail" ;
  
          Connection conn = null;
  
          try {
              conn = dataSource.getConnection();
              PreparedStatement ps = conn.prepareStatement(sql);
              ProductDetailEntity productModel=null; 
              ResultSet result=ps.executeQuery();
              List&lt;ProductDetailEntity&gt; productList=new ArrayList&lt;ProductDetailEntity&gt;();
              if(result != null){
                  while (result.next()){
                      productModel=new ProductDetailEntity();
                      productModel.setProductName(result.getString("name"));
                      productModel.setBrand(result.getString("brand"));
                      productModel.setDescription(result.getString("description"));
                      productModel.setModelnumber(result.getString("modelnumber"));
                      productModel.setDialcolour(result.getString("dialcolour"));
                      productModel.setPrice(Double.parseDouble(result.getString("price")));
                      productModel.setStrap(result.getString("strap"));
                      productModel.setDiameter(result.getString("casediameter"));
                      productModel.setWaterResistant(result.getString("waterresistant"));
                      productModel.setDiscount(result.getString("discount"));
                      productModel.setGender(result.getString("gender"));
  
                      String imageUrl=result.getString("imageURL");
                      ArrayList &lt;String&gt; images=new ArrayList&lt;String&gt;();
                      StringTokenizer strToken=new StringTokenizer(imageUrl, ",");
                      while(strToken.hasMoreTokens()){
                          images.add(strToken.nextToken());
                      }
  
                      productModel.setImage(images);
                      productModel.setMainImage(images.get(0));
  
                      if(result.getString("discount") != "0%"){
                          String discount=productModel.getDiscount();
                           Integer discountNumber=Integer.parseInt(discount.substring(0,discount.indexOf("%")));
                          double discountedPercentage = discountNumber/100.0;
                          double discountedPrice=productModel.getPrice() - (productModel.getPrice()*discountedPercentage);
  
                          System.out.println(discountedPrice);
                          productModel.setDiscountedPrice(discountedPrice);
                      }else{
                          productModel.setDiscountedPrice(productModel.getPrice());
                      }
  
                  System.out.println(productModel.getProductName());
                  productList.add(productModel);
                  if(!flagPopulation)
                  if(result.getString("gender").equalsIgnoreCase("Male")){
                  productListMen.add(productModel);
                  if(!result.getString("discount").equals("0%"))
                  productListMenDisc.add(productModel);
                  }
                  else if(result.getString("gender").equalsIgnoreCase("Female")){
                      productListWomen.add(productModel);
                      if(!result.getString("discount").equals("0%"))
                          productListWomenDisc.add(productModel);
                  }
                  else{
                      productListChild.add(productModel);
                      if(!result.getString("discount").equals("0%"))
                          productListChildDisc.add(productModel);
                  }
  
                  }
              }
  
              flagPopulation=true;
              ps.close();
              return productList;
  
          } catch (SQLException e) {
              throw new RuntimeException(e);
  
          } finally {
              if (conn != null) {
                  try {
                      conn.close();
                  } catch (SQLException e) {}
              }
          }
      }
  
      @Override
      public List&lt;ProductDetailEntity&gt; productDetailsListMen() {
          return productListMen;
      }
  
      @Override
      public List&lt;ProductDetailEntity&gt; productDetailsListWomen() {
          return productListWomen;
      }
  
      @Override
      public List&lt;ProductDetailEntity&gt; productDetailsListChild() {
          return productListChild;
      }
  
      @Override
      public List&lt;ProductDetailEntity&gt; productDetailsListMenDiscount() {
          return productListMenDisc;
      }
  
      @Override
      public List&lt;ProductDetailEntity&gt; productDetailsListWomenDiscount() {
          return productListWomenDisc;
      }
  
      @Override
      public List&lt;ProductDetailEntity&gt; productDetailsListChildDiscount() {
          return productListChildDisc;
      }
       @Override
        public void addProduct(ProductDetailEntity product) {
         String sql = "INSERT INTO ProductDetail " +
           "( name, brand, description , modelnumber, dialcolour , strap , casediameter ,"
           + "waterresistant , price , discount,gender,imageURL) VALUES (?, ?, ?, ? ,? ,? ,? ,? ,? ,?,?,?)";
  
         Connection conn = null;
  
         try {
          conn = dataSource.getConnection();
          PreparedStatement ps = conn.prepareStatement(sql);
          ps.setString(1, product.getProductName());
          ps.setString(2, product.getBrand());
          ps.setString(3, product.getDescription());
          ps.setString(4, product.getModelnumber());
          ps.setString(5, product.getDialcolour());
          ps.setString(6,product.getStrap());
          ps.setString(7, product.getDiameter());
          ps.setString(8,product.getWaterResistant());
          ps.setDouble(9, Double.parseDouble(product.getPricetext()));
          ps.setString(10,product.getDiscount()+"%");
          ps.setString(11,product.getGender());
          ps.setString(12,product.getMainImage());
  
          ps.executeUpdate();
          ps.close();
  
         } catch (SQLException e) {
          throw new RuntimeException(e);
  
         } finally {
          if (conn != null) {
           try {
            conn.close();
           } catch (SQLException e) {}
          }
         }
  
        }
  
  }
  </code></pre>