Hi Everybody
I tried and failed to display images of employees in jTable.
I have a MySQL Table which have 4 fields - ID,Name.Phone,Photo(Blob data type). Now I am able to retrive data from this table and display it in JLabel with other data in JTextField, but How can I show the image of employee in jTable if I need a list of all 60 employees details.
MEANS I want jTable sholud show me detail like this
Till now I am able to get see the text data in jTable but not able to get the image. Here what I have done to see the image (Using Netbeans 7.1)

    public class mytable
        Connection con;
        PreparedStatement psmt;
        public ResultSet rs;

        public void mytableFunction() {
            final Object[] columnNames=new String[] {"Room No.","Room Type","Bed Type","Tariff Per Room"};
            DefaultTableModel dtm=new DefaultTableModel(columnNames,0);
                Class .forName("com.mysql.jdbc.Driver");
                con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employee","root","");
                String query = "select * from personaldetail";
                psmt = con.prepareStatement(query);
                int i = 0;
                    String var1=rs.getString(1);
                    String var2=rs.getString(2);
                    String var3=rs.getString(3);

                    //String var4=Integer.toString(rs.getInt(4));

                    dtm.addRow(new Vector());
                    dtm.setValueAt(var1, i, 0);
                    dtm.setValueAt(var2, i, 1);
                    dtm.setValueAt(var3, i, 2);

                    //dtm.setValueAt(var4, i, 3);
                   jTable1.getColumnModel().getColumn(3).setCellRenderer(new ImageRenderer(rs));
            catch(Exception e)
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            mytable mtb=new mytable();
        class ImageRenderer extends DefaultTableCellRenderer
    ImageIcon format;
        ResultSet rs;
        public ImageRenderer(ResultSet rs1)
        public Component getTableCellRendererComponent(JTable table,Object value, boolean isSelected,boolean hasFocus, int row, int column)
            JLabel label = new JLabel();
                byte[] imagedata=rs.getBytes(4);
                format=new ImageIcon(imagedata);
                if (value!=null) {
                    //value is parameter which filled by byteOfImage
            catch(Exception ex){}
            return label;

Thank you for any suggestion or help

a suggestion:

catch(Exception ex){}
            return label;

you're hiding your exceptions, print your stacktrace there.
what IDE you're using is not really relevant, what is, is whether or not you got an error message and, if so, which one.

why are you trying to read your blob into an Ineger?

take a look at this page: link

This article has been dead for over six months. Start a new discussion instead.