I know we can enable multi-selection using fc.setMultiSelectionEnabled(true)
. But I need a way to add all the selected
files into the database.
I've tried using getFilesSelected()
but the problem is that when I hit enter, only the first selected image is added to the database.
This is what I've tried,
fc.addChoosableFileFilter(new ImageFilter());
if (fc.showOpenDialog(btnBrowse) == JFileChooser.APPROVE_OPTION){
textField.setEditable(true);
img_name.setEditable(true);
textField.setText(fc.getSelectedFile().getAbsolutePath());
img_name.setText(fc.getSelectedFile().getAbsolutePath().substring(fc.getSelectedFile().getAbsolutePath().lastIndexOf("\\")+1));
String ext = fc.getSelectedFile().getAbsolutePath().substring(fc.getSelectedFile().getAbsolutePath().lastIndexOf("\\")+1);
file_ext = ext.substring(ext.indexOf('.'),(ext.length()));
String query = " insert into load_images(format,image_name,file_loc,photo,date_field) values (?,?,?,?,?)";
preparedStmt = con.prepareStatement(query);
preparedStmt.setString (1,file_ext);
preparedStmt.setString (2,img_name.getText());
preparedStmt.setString (3, textField.getText());
File f=new File(textField.getText());
int size=(int) f.length();
FileInputStream fis=new FileInputStream(f);
preparedStmt.setBinaryStream(4,fis,size);
preparedStmt.setTimestamp(5, getCurrentTimeStamp());
preparedStmt.execute();