this is the code I create to import pics

select image:

JFileChooser chooser = new JFileChooser();
        File f = chooser.getSelectedFile();
        filename = f.getAbsolutePath();



           File image = new File (filename);
           FileInputStream fis = new FileInputStream(filename);

          ByteArrayOutputStream  bos = new ByteArrayOutputStream();

           byte[] buf = new byte[1024];

           for (int readNum; (!=-1; ){


            bill_image = bos.toByteArray();

       catch(Exception e){
       JOptionPane.showMessageDialog(null, e);

save it in SQL :

                String sql= "INSERT INTO Pics (Invoicenumber, Photo) VALUES (?,?)";
                pst.setString(1, LBL2.getText());
                pst.setBytes(2, bill_image);

                JOptionPane.showMessageDialog(null, "Data saved");

            }catch (Exception e){
                JOptionPane.showMessageDialog(null, e);

              catch(Exception e){        


but now to retrieve those pics?
I've made a simple code but it doesnt work if the pics has the some InvoiceNumber.
this is the code I use to get pics:

 String b = jTextField1.getText();
          int row = jTable1.getSelectedRow();

            String Table_click1 =(jTable1.getModel().getValueAt(row, 0).toString());

       String sql = "Select Photo from Pics where InvoiceNumber='"+Table_click1+"' ";

       pst = conn.prepareStatement(sql);
       rs = pst.executeQuery();

       byte[] imagedata =rs.getBytes("Photo");
       format = new ImageIcon(imagedata);



       }catch(Exception e){


if pics has different Invoice Number it show the pics. but if has the some it show only the first row pic.

I want to give the user the chance to import as much pics as he want for the products and retrieve those. not all in the some time

if you have multiple results, the ResultSet will have multiple rows in it. Iterate over those rows, rather than just picking the first one and discarding the rest.
so something like

while ( {

I put while, and it show the 2nd row image. select the first row. it show the pic of the 2nd, select the 3rd show the 2nd again. select a row with a different Invoice Number, it show the pic, but when select a row with some id, it still show the 2nd row image

you do need to THINK about what you do inside that while...