title: How to fix "Failed to obtain JDBC Connection" datasource error in my java application
body: <p>I have a little training project running under Java Spring MVC and using MySQL on WAMP Server), it was working but i cloned it and had to reinstall database (restored from a dump) and Wamp64 also, but now my java application cannot connect and i get different errors.</p>
  
  <p>In IntelliJ IDEA when i test the connection to the database, the connection is successfull, even in phpmyadmin, but not when i launch my application.</p>
  
  <p><code>jdbc:mysql://localhost:3306/library?serverTimezone=UTC</code>  (i had to use server timezone to fixe timezone error)</p>
  
  <p>It's looking like my java app doesn't use the good datasource configuration, and instead use the old one but i can't figure out why.</p>
  
  <p>My application is using SOAP protocol to connect to my webservices.</p>
  
  <p>The main error is a javaNullPointer exception on the line where i try to get the user from database trough an input form.</p>
  
  <p>The other error is (when i go in debug mode):</p>
  
  <blockquote>
    <p>Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: AccÃ¨s refusÃ© pour l'utilisateur: 'root'@'@localhost' (mot de passe: OUI) error.</p>
  </blockquote>
  
  <p>This project was cloned from an old project. I suppose there is somewhere an old datasource used by the application.</p>
  
  <p>It looks like my application uses old login settings for mysql (login: root, password: password). I recently changed the login information to my database, to an "admin_library" login that has all the privileges and a password. </p>
  
  <p>I invalidated and restarted the IntelliJ cache, made an "mvn clean install", but when I run my two tomcat servers (one for the webservice, another one for the soap webserviceclient), my login screen appears but I have a null point exception (apparently due to a database connection problem.</p>
  
  <p>Here is my configuration:</p>
  
  <p><strong>pom.xml:</strong></p>
  
  <pre><code>&lt;dependency&gt;
                  &lt;groupId&gt;mysql&lt;/groupId&gt;
                  &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
                  &lt;version&gt;8.0.15&lt;/version&gt;
              &lt;/dependency&gt;
  </code></pre>
  
  <p><strong>WEB-INF/SpringMVCDispatcher-servlet.xml:</strong></p>
  
  <pre><code>&lt;!-- CONFIG JDBC DATASOURCE // --&gt;
      &lt;bean id = "jdbcTemplate"
            class = "org.springframework.jdbc.core.JdbcTemplate"&gt;
          &lt;property name = "dataSource" ref = "dataSource" /&gt;
      &lt;/bean&gt;
      &lt;bean id = "dataSource"
            class = "org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name = "driverClassName" value = "com.mysql.jdbc.Driver"/&gt;
          &lt;property name = "url" value = "jdbc:mysql://localhost:3306/library"/&gt;
          &lt;property name = "username" value = "admin_library"/&gt;
          &lt;property name = "password" value = "password"/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <pre><code>Type Rapport d'exception
  
  message Request processing failed; nested exception is com.sun.xml.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: AccÃ¨s refusÃ© pour l'utilisateur: 'root'@'@localhost' (mot de passe: OUI) Please see the server log to find more detail regarding exact cause of the failure.
  
  description Le serveur a rencontré une erreur interne qui l'a empêché de satisfaire la requête.
  
  exception
  
  org.springframework.web.util.NestedServletException: Request processing failed; nested exception is com.sun.xml.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: AccÃ¨s refusÃ© pour l'utilisateur: 'root'@'@localhost' (mot de passe: OUI) Please see the server log to find more detail regarding exact cause of the failure.
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:901)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
      org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  cause mère
  
  com.sun.xml.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: AccÃ¨s refusÃ© pour l'utilisateur: 'root'@'@localhost' (mot de passe: OUI) Please see the server log to find more detail regarding exact cause of the failure.
      com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:193)
      com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:128)
      com.sun.xml.ws.client.sei.StubHandler.readResponse(StubHandler.java:253)
      com.sun.xml.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:206)
      com.sun.xml.ws.db.DatabindingImpl.deserializeResponse(DatabindingImpl.java:293)
      com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:119)
      com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:92)
      com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:161)
      com.sun.proxy.$Proxy47.findByEmail(Unknown Source)
      fr.projet3.library.controller.LoginController.postLogin(LoginController.java:57)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.base/java.lang.reflect.Method.invoke(Method.java:566)
      org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:215)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:142)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:998)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:901)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:875)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
      org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  note La trace complète de la cause mère de cette erreur est disponible dans les fichiers journaux de ce serveur.
  
  </code></pre>
  
  <p>A look into the controller:</p>
  
  <pre class="lang-java prettyprint-override"><code>@PostMapping(value = {"/login","/", ""})
      public String postLogin(@Valid @ModelAttribute("userLoginForm")UserLoginForm userLoginForm, BindingResult bindingResult, ModelMap modelMap, HttpSession session){
          if(!bindingResult.hasErrors()){
  
              UserWS u = libraryWS.findByEmail(userLoginForm.getEmail());
              if(u == null){
                  return "login";
              }
              session.setAttribute("currentUser", u);
  
              return "redirect:/userloan";
          }
          return "login";
      }
  </code></pre>