Note that there are some explanatory texts on larger screens.

plurals
  1. POI can't show photo blob more than once
    text
    copied!<p>I have a database with photos for each person. I have a class that shows the photos of the people. When the class is running first, it stores the foto locally, and then another method takes it and displays it. The problem is that the class works correctly ONLY the first time! Every other name selection displays the first picture. Please help me to identify where does this happen!</p> <p>Here is my Class:</p> <pre><code>public class Profile extends JFrame { int x; JLabel label; Image img; ImageIcon pic; JPanel panel; private JTextPane namepanel = new JTextPane(); private JLabel namelabel = new JLabel(); private JLabel lastnamelabel = new JLabel(); private JTextPane lastnamepanel = new JTextPane(); ResultSet resultSet; private JButton add = new JButton(); private JButton remove = new JButton(); public Profile() { try { //getData(x); //showImage(); //jbInit(); } catch (Exception e) { e.printStackTrace(); } } public void getData(int p_id) throws Exception { Login login = new Login(); String url = "jdbc:oracle:thin:@localhost:1521:ORCL"; String username = login.getUsername(); String password = login.getPassword(); Connection conn = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection(url, username, password); System.out.println("At the profile class id = " + p_id); String sql = "SELECT foto, name, surname FROM criminals WHERE id = " + p_id; System.out.println(sql); PreparedStatement stmt = conn.prepareStatement(sql); resultSet = stmt.executeQuery(); while (resultSet.next()) { namepanel.setText(resultSet.getString(2)); lastnamepanel.setText(resultSet.getString(3)); File image = new File("java.jpg"); FileOutputStream fos = new FileOutputStream(image); byte[] buffer = new byte[256]; // Get the binary stream of our BLOB data InputStream is = resultSet.getBinaryStream(1); int bytes = 0; while ((bytes = is.read(buffer)) &gt; 0) { fos.write(buffer, 0, bytes); } showImage(); fos.close(); } } catch (SQLException e) { e.printStackTrace(); } finally { if (conn != null &amp;&amp; !conn.isClosed()) { conn.close(); } } } public void showImage() throws Exception { this.getContentPane().removeAll(); img = null; img = new ImageIcon("java.jpg").getImage(); pic = null; pic = new ImageIcon(img); label = new JLabel("", pic, JLabel.CENTER); panel = new JPanel(new BorderLayout()); panel.setBounds(new Rectangle(0, 0, 340, 310)); namepanel.setBounds(new Rectangle(340, 30, 295, 35)); namelabel.setText("Name"); namelabel.setBounds(new Rectangle(340, 0, 295, 30)); lastnamelabel.setText("Surname"); lastnamelabel.setBounds(new Rectangle(340, 65, 295, 30)); lastnamepanel.setBounds(new Rectangle(340, 105, 295, 35)); add.setText("add"); add.setBounds(new Rectangle(440, 175, 255, 40)); remove.setText("remove"); remove.setBounds(new Rectangle(440, 240, 255, 35)); panel.add(label, null); panel.add(label, BorderLayout.CENTER); this.getContentPane().setLayout(null); this.setSize(new Dimension(1148, 336)); this.getContentPane().add(remove, null); this.getContentPane().add(add, null); this.getContentPane().add(lastnamepanel, null); this.getContentPane().add(lastnamelabel, null); this.getContentPane().add(namelabel, null); this.getContentPane().add(namepanel, null); this.getContentPane().add(panel, null); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload