title: Spring mvc with jdbc template
body: <p>I want to implements simple login with spring mvc and jdbc template. but I am getting null pointer exception. I have included spring-core.jar,spring-jdbc.jar,spring-txn.jar,spring-web.jar..</p>
  
  <pre><code>    ****Complete stack trace:****
  
        May 17, 2015 6:54:54 PM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet [login] in context with path [/MVCWithJDBC] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
  java.lang.NullPointerException
      at com.mvc.dao.LoginDAOImpl.getLoginDetails(LoginDAOImpl.java:25)
      at com.mvc.controller.LoginController.handleRequest(LoginController.java:30)
      at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:745)
  
      **Web.xml:**
  
          &lt;?xml version="1.0" encoding="UTF-8"?&gt;
          &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
            &lt;display-name&gt;MVCMultpleActions&lt;/display-name&gt;
            &lt;welcome-file-list&gt;
             &lt;welcome-file&gt;login.jsp&lt;/welcome-file&gt;
            &lt;/welcome-file-list&gt;
             &lt;servlet&gt;
              &lt;servlet-name&gt;login&lt;/servlet-name&gt;
              &lt;servlet-class&gt;
                   org.springframework.web.servlet.DispatcherServlet
                &lt;/servlet-class&gt;
              &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
            &lt;/servlet&gt;
            &lt;servlet-mapping&gt;
              &lt;servlet-name&gt;login&lt;/servlet-name&gt;
              &lt;url-pattern&gt;*.ak&lt;/url-pattern&gt;
            &lt;/servlet-mapping&gt;  
          &lt;/web-app&gt;
  
      **login-servlet.xml:**
  
          &lt;?xml version="1.0" encoding="UTF-8"?&gt;  
          &lt;beans  
              xmlns="http://www.springframework.org/schema/beans"  
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
              xmlns:p="http://www.springframework.org/schema/p"  
              xsi:schemaLocation="http://www.springframework.org/schema/beans  
                         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;  
           &lt;bean name="/login.ak" class="com.mvc.controller.LoginController"&gt; &lt;/bean&gt;
           &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
                &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt;
                &lt;property name="suffix" value=".jsp" /&gt;
           &lt;/bean&gt;
          &lt;bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;  
          &lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /&gt;  
          &lt;property name="url" value="jdbc:oracle:thin:@localhost:1521:xe" /&gt;  
          &lt;property name="username" value="system" /&gt;  
          &lt;property name="password" value="mysql" /&gt;  
          &lt;/bean&gt;     
  
  
          &lt;bean id="logindao" class="com.mvc.dao.LoginDAOImpl"&gt;  
          &lt;property name="dataSource" ref="ds"&gt;&lt;/property&gt; 
          &lt;/bean&gt;
          &lt;/beans&gt;
  
          **DAO Classes:**
          package com.mvc.dao;
  
      import javax.sql.DataSource;
  
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.jdbc.core.JdbcTemplate;
      import org.springframework.jdbc.core.support.JdbcDaoSupport;
      import org.springframework.jdbc.datasource.DriverManagerDataSource;
  
      import com.mvc.mapper.*;
      import com.mvc.dto.LoginDTO;
  
      public class LoginDAOImpl extends JdbcDaoSupport implements LoginDAO {
  
          @Override
          public LoginDTO getLoginDetails(String userName) {
              // TODO Auto-generated method stub
              System.out.println("userName:"+userName);
              String query="select password from Login where userName=?";
              System.out.println("query"+query);
              return getJdbcTemplate.queryForObject(query,new Object[]{userName},new LoginMapper());
  
              }
  
      }
  
      **Controller:**
  
          package com.mvc.controller;
  
          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;
  
          import org.springframework.context.ApplicationContext;
          import org.springframework.context.support.ClassPathXmlApplicationContext;
          import org.springframework.web.servlet.ModelAndView;
          import org.springframework.web.servlet.mvc.Controller;
  
          import com.mvc.dao.LoginDAOImpl;
          import com.mvc.dto.LoginDTO;
  
          public class LoginController implements Controller{
  
              @Override
              public ModelAndView handleRequest(HttpServletRequest req,
                      HttpServletResponse res) throws Exception {
                  // TODO Auto-generated method stub
                  String name=req.getParameter("userName");
                  String password=req.getParameter("password");
                  LoginDAOImpl login=new LoginDAOImpl();
                  LoginDTO loginDto=new LoginDTO();
                  loginDto.setUserName(name);
                  loginDto.setPassword(password);
                  System.out.println("pw:"+password);
                  String pw=login.getLoginDetails("admin").getPassword();
                  System.out.println("dao pw:"+pw);
                  if(password.equalsIgnoreCase(pw))
                  {
                       String message = "HELLO "+name;  
                        return new ModelAndView("hellopage", "message", message);  
                    }  
                    else{  
                              return new ModelAndView("errorpage", "message","Sorry, username or password error");  
                          }  
  
              }
  
  
          }
  </code></pre>