Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Get a avatar from the database.
- *
- * @param avatarId The id of a avatar.
- * @return The InputStream.
- */
- public static byte[] getAvatarFromDatabase(int avatarId) {
- Connection conn = null;
- try {
- conn = ConnectionPool.getInstance().getConnection();
- try (PreparedStatement p = conn
- .prepareStatement("SELECT avatar FROM \"user\" WHERE id = ?")) {
- p.setInt(1, avatarId);
- try (ResultSet rst = p.executeQuery()) {
- if (rst.next()) {
- return rst.getBytes("avatar");
- }
- }
- }
- } catch (SQLException | StorageException e) {
- e.printStackTrace();
- } finally {
- ConnectionPool.getInstance().releaseConnection(conn);
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement