Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void setThumbnail(BufferedImage thumbnail) throws SQLException, IOException {
- TinyLink tinyLink = this;
- if (thumbnail != null) {
- Connection connection = databaseInstance.getConnection();
- if (connection == null) return;
- String statement = "UPDATE TinyLink set thumbnail=? WHERE id=?";
- PreparedStatement preparedStatement = connection.prepareStatement(statement);
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- ImageIO.write(thumbnail, "jpg", byteArrayOutputStream);
- InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
- preparedStatement.setBinaryStream(1, inputStream);
- preparedStatement.setInt(2, tinyLink.id);
- byteArrayOutputStream.flush();
- byteArrayOutputStream.close();
- inputStream.close();
- preparedStatement.executeUpdate();
- preparedStatement.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement