Advertisement
Guest User

Untitled

a guest
May 4th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. JLabel lblPicture = new JLabel("New label");
  2. lblPicture.setBounds(34, 82, 245, 184);
  3. contentPane.add(lblPicture);
  4.  
  5. try {
  6. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/javadb", "root", "");
  7.  
  8.  
  9. byte b[];
  10. Blob blob;
  11.  
  12. PreparedStatement ps=conn.prepareStatement("select * from images");
  13. ResultSet rs=ps.executeQuery();
  14.  
  15. while(rs.next()){
  16. blob=rs.getBlob("img");
  17. b=blob.getBytes(1,(int)blob.length());
  18.  
  19. BufferedImage img = null;
  20. img = ImageIO.read(new ByteArrayInputStream(b));
  21. lblPicture.setIcon(new ImageIcon(img));
  22. }
  23.  
  24.  
  25.  
  26.  
  27.  
  28. } catch (SQLException e) {
  29. e.printStackTrace();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement