SHARE
TWEET

Adding Thumbnail

MOSDEV Dec 7th, 2019 123 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void setThumbnail(BufferedImage thumbnail) throws SQLException, IOException {
  2.         TinyLink tinyLink = this;
  3.         if (thumbnail != null) {
  4.             Connection connection = databaseInstance.getConnection();
  5.             if (connection == null) return;
  6.             String statement = "UPDATE TinyLink set thumbnail=? WHERE id=?";
  7.             PreparedStatement preparedStatement = connection.prepareStatement(statement);
  8.  
  9.             ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  10.             ImageIO.write(thumbnail, "jpg", byteArrayOutputStream);
  11.             InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
  12.  
  13.             preparedStatement.setBinaryStream(1, inputStream);
  14.             preparedStatement.setInt(2, tinyLink.id);
  15.  
  16.             byteArrayOutputStream.flush();
  17.             byteArrayOutputStream.close();
  18.             inputStream.close();
  19.             preparedStatement.executeUpdate();
  20.             preparedStatement.close();
  21.         }
  22.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top