title: Spring Boot: Jdbc javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify
body: <p>I am currently learning more about implementing JDBC and using databases in a Spring Boot webapp, and I encountered the following Stack Trace written in the bottom of the post.</p>
  
  <p>I have created a simple Employee model, and I am trying to execute some database code on the same class which my main() lies in. The model and the main class are the only two java files existing in this whole project. I am trying to implement the following run() code that overrides the one from the interface, CommandLineRunner, but I do not get the logs that should come after <em>log.info("Part A:")</em>:</p>
  
  <pre><code>log.info("Part A:")
  employees.forEach(employee -&gt; {log.info(employee.toString());
          log.info("part a");});
  </code></pre>
  
  <p>--Things I noticed:</p>
  
  <p>I noticed that the last line of the log before the stack trace starts comes from: "Thread-1" instead of "main". I think that means that a thread from somewhere other than the main encountered an error and closed connection before when it should close normally.</p>
  
  <p>Also, I think that because <strong>HikariPool closed before "peer's close_notify"</strong>, which I presume that it refers to the normal closure of HikariPool, I am not able to see the final bit of logging that I have kept trying to procure. The final bit of logging that I want to see is the logging of the employee that has become inserted into my database.</p>
  
  <p>The final bit of logging that I want to see should be procured from this line of code:</p>
  
  <pre><code>employees.forEach(employee -&gt; {log.info(employee.toString());
          log.info("part a");});
  </code></pre>
  
  <p>--Things to note:</p>
  
  <p>Because of this line in the log, I thought I would see the employee inserted into my database, but when I queried directly on MySQL Command Line Client, it returned an empty set:</p>
  
  <pre><code>2018-11-03 21:08:35.362  INFO 2408 --- [           main] c.j.jdbctest1.JdbcTest1Application       : rows affected: 1
  </code></pre>
  
  <p>I don't understand why <strong>a row has been affected when nothing has been inserted into the database</strong>.</p>
  
  <p>The stacktrace and logs: (The stacktrace pasted below actually repeats itself several more times but I cut it off for brevity.)</p>
  
  <pre><code>2018-11-03 21:08:32.997  INFO 2408 --- [           main] c.j.jdbctest1.JdbcTest1Application       : Starting JdbcTest1Application on KitKat with PID 2408 (C:\Users\Nano\Downloads\jdbc-test1\jdbc-test1\target\classes started by Nano in C:\Users\Nano\Downloads\jdbc-test1\jdbc-test1)
  2018-11-03 21:08:33.003  INFO 2408 --- [           main] c.j.jdbctest1.JdbcTest1Application       : No active profile set, falling back to default profiles: default
  2018-11-03 21:08:33.770  INFO 2408 --- [           main] c.j.jdbctest1.JdbcTest1Application       : Started JdbcTest1Application in 1.024 seconds (JVM running for 1.778)
  2018-11-03 21:08:33.770  INFO 2408 --- [           main] c.j.jdbctest1.JdbcTest1Application       : Creating tables
  2018-11-03 21:08:33.770  INFO 2408 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
  2018-11-03 21:08:34.082  INFO 2408 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
  2018-11-03 21:08:35.135  INFO 2408 --- [           main] c.j.jdbctest1.JdbcTest1Application       : Inserting Baggins Hopkins
  2018-11-03 21:08:35.362  INFO 2408 --- [           main] c.j.jdbctest1.JdbcTest1Application       : rows affected: 1
  2018-11-03 21:08:35.362  INFO 2408 --- [           main] c.j.jdbctest1.JdbcTest1Application       : Querying for employee
  2018-11-03 21:08:36.065  INFO 2408 --- [           main] c.j.jdbctest1.JdbcTest1Application       : Part A:
  2018-11-03 21:08:36.065  INFO 2408 --- [       Thread-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
  Sat Nov 03 21:08:36 KST 2018 WARN: Caught while disconnecting...
  
  EXCEPTION STACK TRACE:
  
  
  
  ** BEGIN NESTED EXCEPTION ** 
  
  javax.net.ssl.SSLException
  MESSAGE: closing inbound before receiving peer's close_notify
  
  STACKTRACE:
  
  javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify
      at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:129)
      at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117)
      at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:308)
      at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)
      at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:255)
      at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:645)
      at java.base/sun.security.ssl.SSLSocketImpl.shutdownInput(SSLSocketImpl.java:624)
      at com.mysql.cj.protocol.a.NativeProtocol.quit(NativeProtocol.java:1312)
      at com.mysql.cj.NativeSession.quit(NativeSession.java:182)
      at com.mysql.cj.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:1750)
      at com.mysql.cj.jdbc.ConnectionImpl.close(ConnectionImpl.java:720)
      at com.zaxxer.hikari.pool.PoolBase.quietlyCloseConnection(PoolBase.java:135)
      at com.zaxxer.hikari.pool.HikariPool.lambda$closeConnection$1(HikariPool.java:441)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      at java.base/java.lang.Thread.run(Thread.java:834)
  
  
  ** END NESTED EXCEPTION **
  </code></pre>
  
  <p>The Java Code:</p>
  
  <pre><code>@SpringBootApplication
  public class JdbcTest1Application implements CommandLineRunner {
      private static final Logger log = LoggerFactory.getLogger(JdbcTest1Application.class);
  
      @Autowired
      JdbcTemplate jdbcTemplate;
  
      public static void main(String[] args) {
          SpringApplication.run(JdbcTest1Application.class, args);
      }
  
      @Override
      public void run(String... args) throws Exception {
          log.info("Creating tables");
  
          jdbcTemplate.execute("DROP TABLE IF EXISTS employees");
          jdbcTemplate.execute("CREATE TABLE employees (emp_id int, name varchar(100), role varchar(100), status varchar(100))");
  
          log.info("Inserting Baggins Hopkins");
          int rowsAffected = jdbcTemplate.update("INSERT INTO EMPLOYEE(EMP_ID, NAME, ROLE, STATUS)"
                  + " VALUES(1,'Baggins Hopkins','thief','WORKING')");
          log.info("rows affected: "+ Integer.toString(rowsAffected));
          log.info("Querying for employee");
          String sql = "SELECT emp_id,name,role,status FROM employees";
          List&lt;Employee&gt; employees = jdbcTemplate.query(sql,(rs, rowNum)-&gt; 
          new Employee(rs.getInt("emp_id"), rs.getString("name"),
                  rs.getString("role"),Status.valueOf(rs.getString("status"))));
          log.info("Part A:");
          employees.forEach(employee -&gt; {log.info(employee.toString());
              log.info("part a");});
  
      }
  }
  </code></pre>
  
  <p>Also just in case this matters, I pasted this code from application.properties:</p>
  
  <pre><code>spring.datasource.url=jdbc:mysql://localhost:3306/employee_database
  spring.datasource.username=employee
  spring.datasource.password=employee
  spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  </code></pre>