code: public BufferedImage getTile( int x, int y, int z ) throws Exception {
          try (PreparedStatement statement = connection.prepareStatement(SELECTQUERY)) {
              statement.setInt(1, z);
              statement.setInt(2, x);
              statement.setInt(3, y);
              ResultSet resultSet = statement.executeQuery();
              if (resultSet.next()) {
                  byte[] imageBytes = resultSet.getBytes(1);
                  boolean orig = ImageIO.getUseCache();
                  ImageIO.setUseCache(false);
                  InputStream in = new ByteArrayInputStream(imageBytes);
                  BufferedImage bufferedImage = ImageIO.read(in);
                  ImageIO.setUseCache(orig);
                  return bufferedImage;
              }
          }
          return null;
      }
docs: Get a Tile image from the database.
  
  @param x
  @param y
  @param z
  @return
  @throws Exception