title: How to catch java.sql.SQLException?
body: <p>I am trying to catch java.sql.SQLException in my java spring boot application. I got a good understanding on how to do so on this <a href="https://www.tutorialspoint.com/jdbc/jdbc-exceptions.htm" rel="nofollow noreferrer">page</a>. But since I am using spring boot my credentials are located in my application.properties file.</p>
  
  <p><strong>my application.properties to this:</strong></p>
  
  <pre><code>spring.datasource.url = jdbc:oracle:thin:@//SomePathURI
  spring.datasource.username= someUser
  spring.datasource.password= somepass
  </code></pre>
  
  <p><strong>Error output</strong></p>
  
  <pre><code>2017-04-04 10:18:13.866 ERROR 11684 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: ORA-01017: invalid username/password; logon denied
  ] with root cause
  
  java.sql.SQLException: ORA-01017: invalid username/password; logon denied
  
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:389) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:382) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:675) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:448) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:383) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at oracle.jdbc.driver.T4CTTIoauthenticate.doOAUTH(T4CTTIoauthenticate.java:776) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:432) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at oracle.jdbc.driver.PhysicalConnection.&lt;init&gt;(PhysicalConnection.java:553) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at oracle.jdbc.driver.T4CConnection.&lt;init&gt;(T4CConnection.java:254) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528) ~[ojdbc6-11.2.0.4.jar:11.2.0.4.0]
      at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310) ~[tomcat-jdbc-8.5.6.jar:na]
      at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203) ~[tomcat-jdbc-8.5.6.jar:na]
      at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:718) ~[tomcat-jdbc-8.5.6.jar:na]
      at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:650) ~[tomcat-jdbc-8.5.6.jar:na]
      at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:468) ~[tomcat-jdbc-8.5.6.jar:na]
      at org.apache.tomcat.jdbc.pool.ConnectionPool.&lt;init&gt;(ConnectionPool.java:143) ~[tomcat-jdbc-8.5.6.jar:na]
      at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118) ~[tomcat-jdbc-8.5.6.jar:na]
      at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107) ~[tomcat-jdbc-8.5.6.jar:na]
  </code></pre>
  
  <p>How can I catch this exception and continue running my application. Rather than having the application automatically stop and displays this error? I don't understand how would I do try catches if my connection is in application.properties.</p>