title: Database connection with Spring Boot Application
body: <p>For the past few days i'm trying to get my Spring Boot Application online on my own server. I have installed MySql and Tomcat on there. It has worked before with a database connection as well, but with my new version it doesn't work anymore for some reason.</p>
  
  <p>My application.properties is below:</p>
  
  <pre><code>spring.jpa.hibernate.ddl-auto=create-drop
  spring.jpa.show-sql=true
  spring.datasource.url=jdbc:mysql://localhost:3306/dbacc
  spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  spring.datasource.username=root
  spring.datasource.password=password
  spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
  spring.h2.console.enabled=true
  </code></pre>
  
  <p>The application does start, but when I try to add a new record to my database I'm getting the following message:</p>
  
  <pre><code>Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
  </code></pre>
  
  <p>Can someone please help me with this issue? Thank you in advance.</p>
  
  <p>Part of the controller:</p>
  
  <pre><code>@RequestMapping(value = "/registration", method = RequestMethod.GET)
  public String registration(Model model) {
      System.out.println("in methode registration (29)");
      model.addAttribute("userForm", new Client());
  
      return "registration";
  }
  
  @RequestMapping(value = "/registration", method = RequestMethod.POST)
  public String registration(@ModelAttribute("userForm") Client userForm, BindingResult bindingResult, Model model) {
      System.out.println("in methode registration (37)");
      clientValidator.validate(userForm, bindingResult);
  
      if (bindingResult.hasErrors()) {
          return "registration";
      }
  
      clientService.save(userForm);
  
      securityService.autologin(userForm.getCompanyName(), userForm.getPasswordConfirm());
  
      return "redirect:/welcome";
  }
  </code></pre>
  
  <p>Client model:</p>
  
  <pre><code>@Entity
  public class Client {
  
  private Long id;
  private String companyName;
  
  private String password;
  private String passwordConfirm;
  
  private String addressStreet;
  private Long addressNumber;
  private String addressNumberAdd;
  private String zipCode;
  private String city;
  
  private String personToContact;
  private String phoneNumber;
  private String email;
  
  //getters and setters
  }
  </code></pre>
  
  <p>pom.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;groupId&gt;nl.insiteweb&lt;/groupId&gt;
  &lt;artifactId&gt;insite&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  
  &lt;name&gt;insiteweb&lt;/name&gt;
  &lt;description&gt;Accountancy systeem voor Insiteweb&lt;/description&gt;
  
  &lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.5.1.RELEASE&lt;/version&gt;
      &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
  &lt;/parent&gt;
  
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
      &lt;java.version&gt;1.8&lt;/java.version&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.itextpdf&lt;/groupId&gt;
          &lt;artifactId&gt;cleanup&lt;/artifactId&gt;
          &lt;version&gt;1.0.1&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.itextpdf&lt;/groupId&gt;
          &lt;artifactId&gt;typography&lt;/artifactId&gt;
          &lt;version&gt;1.0.2&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.itextpdf&lt;/groupId&gt;
          &lt;artifactId&gt;zugferd&lt;/artifactId&gt;
          &lt;version&gt;1.0.1&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.itextpdf&lt;/groupId&gt;
          &lt;artifactId&gt;html2pdf&lt;/artifactId&gt;
          &lt;version&gt;1.0.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.itextpdf&lt;/groupId&gt;
          &lt;artifactId&gt;itext-licensekey&lt;/artifactId&gt;
          &lt;version&gt;2.0.3&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.itextpdf.tool&lt;/groupId&gt;
          &lt;artifactId&gt;xfaworker&lt;/artifactId&gt;
          &lt;version&gt;5.5.10&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.itextpdf.tool&lt;/groupId&gt;
          &lt;artifactId&gt;itext-licensekey&lt;/artifactId&gt;
          &lt;version&gt;1.0.4&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.opensaml&lt;/groupId&gt;
          &lt;artifactId&gt;opensaml&lt;/artifactId&gt;
          &lt;version&gt;2.6.4&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;net.sf.ehcache&lt;/groupId&gt;
          &lt;artifactId&gt;ehcache-core&lt;/artifactId&gt;
          &lt;version&gt;2.2.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
          &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt;
          &lt;artifactId&gt;tomcat-embed-jasper&lt;/artifactId&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;jstl&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.h2database&lt;/groupId&gt;
          &lt;artifactId&gt;h2&lt;/artifactId&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;repositories&gt;
      &lt;repository&gt;
          &lt;id&gt;itext&lt;/id&gt;
          &lt;name&gt;iText Repository - releases&lt;/name&gt;
          &lt;url&gt;https://repo.itextsupport.com/releases&lt;/url&gt;
      &lt;/repository&gt;
  
      &lt;repository&gt;
          &lt;id&gt;iText Repository&lt;/id&gt;
          &lt;name&gt;iText Repository-releases&lt;/name&gt;
          &lt;url&gt;https://repo.itextsupport.com/releases&lt;/url&gt;
      &lt;/repository&gt;
  &lt;/repositories&gt;
  
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;1.5.2.RELEASE&lt;/version&gt;
  
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;repackage&lt;/goal&gt;
                      &lt;/goals&gt;
  
                      &lt;configuration&gt;
                          &lt;sources&gt;
                              &lt;source&gt;facturen/&lt;/source&gt;
                          &lt;/sources&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>
  
  <p>And the errors I get from logs/catalina.out</p>
  
  <pre><code>Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:     Communications link failure
  
  The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_121]
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_121]
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_121]
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_121]
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.40.jar:5.1.40]
  at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989) ~[mysql-connector-java-5.1.40.jar:5.1.40]
  at com.mysql.jdbc.MysqlIO.&lt;init&gt;(MysqlIO.java:341) ~[mysql-connector-java-5.1.40.jar:5.1.40]
  at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2251) ~[mysql-connector-java-5.1.40.jar:5.1.40]
  at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284) ~[mysql-connector-java-5.1.40.jar:5.1.40]
  at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083) ~[mysql-connector-java-5.1.40.jar:5.1.40]
  at com.mysql.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:806) ~[mysql-connector-java-5.1.40.jar:5.1.40]
  at com.mysql.jdbc.JDBC4Connection.&lt;init&gt;(JDBC4Connection.java:47) ~[mysql-connector-java-5.1.40.jar:5.1.40]
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_121]
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_121]
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_121]
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_121]
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:425) ~[mysql-connector-java-5.1.40.jar:5.1.40]
  at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410) ~[mysql-connector-java-5.1.40.jar:5.1.40]
  at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328) ~[mysql-connector-java-5.1.40.jar:5.1.40]
  at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310) ~[tomcat-jdbc-8.5.11.jar:na]
  at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203) ~[tomcat-jdbc-8.5.11.jar:na]
  at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:732) ~[tomcat-jdbc-8.5.11.jar:na]
  at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:664) ~[tomcat-jdbc-8.5.11.jar:na]
  at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:479) ~[tomcat-jdbc-8.5.11.jar:na]
  at org.apache.tomcat.jdbc.pool.ConnectionPool.&lt;init&gt;(ConnectionPool.java:154) ~[tomcat-jdbc-8.5.11.jar:na]
  at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118) ~[tomcat-jdbc-8.5.11.jar:na]
  at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107) ~[tomcat-jdbc-8.5.11.jar:na]
  at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131) ~[tomcat-jdbc-8.5.11.jar:na]
  at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
  at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:386) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
  at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:87) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
  ... 132 common frames omitted
  Caused by: java.net.ConnectException: Connection refused (Connection refused)
  at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_121]
  at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_121]
  at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_121]
  at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_121]
  at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_121]
  at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_121]
  at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211) ~[mysql-connector-java-5.1.40.jar:5.1.40]
  at com.mysql.jdbc.MysqlIO.&lt;init&gt;(MysqlIO.java:300) ~[mysql-connector-java-5.1.40.jar:5.1.40]
  ... 156 common frames omitted
  </code></pre>