Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1.  
  2.     /**
  3.      * Get a avatar from the database.
  4.      *
  5.      * @param avatarId The id of a avatar.
  6.      * @return The InputStream.
  7.      */
  8.     public static byte[] getAvatarFromDatabase(int avatarId) {
  9.         Connection conn = null;
  10.         try {
  11.             conn = ConnectionPool.getInstance().getConnection();
  12.             try (PreparedStatement p = conn
  13.                     .prepareStatement("SELECT avatar FROM \"user\" WHERE id = ?")) {
  14.                 p.setInt(1, avatarId);
  15.                 try (ResultSet rst = p.executeQuery()) {
  16.                     if (rst.next()) {
  17.                         return rst.getBytes("avatar");
  18.                     }
  19.                 }
  20.             }
  21.         } catch (SQLException | StorageException e) {
  22.             e.printStackTrace();
  23.         } finally {
  24.             ConnectionPool.getInstance().releaseConnection(conn);
  25.         }
  26.         return null;
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement