PostgreSQL
 sql >> Baza danych >  >> RDS >> PostgreSQL

Wyświetlanie obrazu z bazy PostgreSQL, bajta

Coś takiego:

// Run a query again the IMAGE table to fetch the image with the given id
public Image readImage(Connection conn, int id) throws SQLException {
  PreparedStatement pstmt = null;
  try {
    pstmt = conn.prepareStatement("SELECT contents FROM image WHERE id = ?");
    pstmt.setInt(1, id); 
    ResultSet rs = ps.executeQuery();
    if (rs.next()) {
      InputStream is = rs.getBinaryStream(1);
      return ImageIO.read(is);
    } else {
      return null;
    }
  } finally {
    if (pstmt != null) {
      try {
        pstmt.close();
      } catch (SQLException ignored) {
      }
    }
  }
}

// Display the given Image on a Swing frame
public void showImage(final Image img) {
  JFrame frame = new JFrame("Image");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setSize(img.getWidth(), img.getHeight());
  frame.add(new JPanel() {
    public void paint(Graphics g) {
      g.drawImage(img, 0, 0, null);
    }
  });
  frame.show();
}

może pracować dla Ciebie.




  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Postgres Query Plan, dlaczego szacowanie wierszy jest tak błędne

  2. Dlaczego potrzebujemy brokerów komunikatów, takich jak RabbitMQ, nad bazą danych, taką jak PostgreSQL?

  3. Kolumna zmiany Rails Migration w celu użycia tablic Postgres

  4. Aktualizacja bazy danych do PostgreSQL w wersji 10 — co powinieneś wiedzieć

  5. Przegląd pgModeler dla PostgreSQL