code: private String getSqlState(SQLException ex) {
      String sqlState = ex.getSQLState();
      if (sqlState == null) {
        SQLException nestedEx = ex.getNextException();
        if (nestedEx != null) {
          sqlState = nestedEx.getSQLState();
        }
      }
      return sqlState;
    }
docs: Gets the SQL state code from the supplied {@link SQLException exception}.
  <p>Some JDBC drivers nest the actual exception from a batched update, so we
  might need to dig down into the nested exception.
  
  @param ex the exception from which the {@link SQLException#getSQLState() SQL state}
  is to be extracted
  @return the SQL state code