title: PreparedStatement won't ever timeout even if explicitly set
body: <p>I am trying to simulate an scenario where my service loses connection to a database and cannot do an <code>INSERT</code> by blocking the connection with iptables, but I can't make the <code>executeQuery()</code> method to timeout.</p>
  
  <p>What I did is setting a timeout for the PreparedStatement like this <code>statement.setQueryTimeout(5)</code>. Here is the code.</p>
  
  <pre><code>HikariConfig config = new HikariConfig();
  
  config.setJdbcUrl("jdbc:mysql://db-url/db");
  config.setUsername("user");
  config.setPassword("passwd");
  
  config.setMaximumPoolSize(10);
  config.setAutoCommit(false);
  config.setConnectionTimeout(5000);
  config.setDriverClassName("com.mysql.jdbc.Driver");
  config.addDataSourceProperty("cachePrepStmts", "true");
  config.addDataSourceProperty("prepStmtCacheSize", "250");
  config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
  config.addDataSourceProperty("autoReconnect", "true");
  
  final HikariDataSource pool = new HikariDataSource(config);
  
  final String query = "INSERT INTO xtable VALUES (?, ?, ?, ?, ?)";
  
  try ( Connection connection = pool.getConnection() )
  {
      try ( PreparedStatement statement = connection.prepareStatement(query) )
      {
          // this is what I expect to work
          statement.setQueryTimeout(5);
  
          for ( Info info : infos )
          {
              statement.setString(1, info.getValue1());
              statement.setString(2, info.getValue2());
              statement.setString(3, info.getValue3());
              statement.setString(4, info.getValue4());
              statement.setString(5, info.getValue5());
  
              try
              {
                  System.out.println("Waiting");
                  Thread.sleep(5000);
                  // I use this sleep to ban the database url with iptables
                  // to simulate a disconnection
                  System.out.println("Waited");
              }
              catch ( InterruptedException e )
              {
                  e.printStackTrace();
              }
  
              System.out.println("Before executeQuery");
              statement.executeQuery();
              // I assumed that this would timeout after 5 seconds
              // But it never reaches the next System.out.print
              System.out.println("After executeQuery");
          }
      }
  
      System.out.println("Before commit");
      connection.commit();
      System.out.println("After commit");
  }
  catch ( SQLException e )
  {
      log.error("Couldn't execute query", e);
  }
  </code></pre>
  
  <p>The output would be:</p>
  
  <pre><code>Waiting
  Waited
  Before executeQuery
  </code></pre>
  
  <p>and then it hangs forever... What can I do to make it throw an Exception?</p>