so as above i need to upload more the one image to my database and i'm using Jfilechooser to select my files my code works fine for only one image at a time and i have a blob column to save my images in it
the code for my sql query
try {
PreparedStatement pst =null;
ResultSet rst=(ResultSet) pst;
Connection con=(Connection) DriverManager.getConnection("jdbc:mysql://localhost/iqari", "root","");
String sql="UPDATE first SET test = ? WHERE id = ?";
pst=(PreparedStatement) con.prepareStatement(sql);
int row = masterTable.getSelectedRow();
Object d = masterTable.getValueAt(row, 0);
pst.setBytes(1,person_image);
pst.setObject(2,d);
pst.execute();
JOptionPane.showMessageDialog(mainPanel, "done");
} catch (Exception e) {
System.out.println(e.getMessage());
}
the code for attaching my image EDITED
JFileChooser chooser =new JFileChooser();
chooser.setMultiSelectionEnabled(true);
chooser.showOpenDialog(null);
File[] files = chooser.getSelectedFiles();
for (File f : files) {
filename = f.getAbsolutePath();
try
{
File image2 = new File(filename);
FileInputStream fis = new FileInputStream(image2);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
for(int readNum; (readNum = fis.read(buf)) != -1;){
bos.write(buf, 0, readNum);
}
person_image = bos.toByteArray();
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
any help can be useful guys.