vendredi 31 juillet 2015

Error : java.lang.NullPointerException when retrieve Image(Blob) data from SQLite database [duplicate]

This question already has an answer here:

I am trying to retrieve Image(Blob) Data from database But it gives my null pointer exception . What is wrong with it ? Here is the Code

    JButton show = new JButton("New button");
    show.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try{
                String iid="10";
                //iid=id.getText().toString();
                String q="select * from image where id='"+iid+"'";

                PreparedStatement ps=con.prepareStatement(q);
                //ps.setString(1, id.getText());
                ps.executeQuery();
                ResultSet rs=ps.executeQuery();         
                while (rs.next()) {
                    InputStream in = rs.getBinaryStream("image");
                    bufImg = ImageIO.read(in);
                    img.setIcon(new ImageIcon (bufImg));
                }
                rs.close();
                ps.close();


                }catch(Exception c)
                {
                    c.printStackTrace();
                }
        }
    });

Aucun commentaire:

Enregistrer un commentaire