I want to upload a path of an image to mysql database but whenever i tried to upload it, it always upload the path without '/'. example i have a file in src/upload/nameofimage.jpg, in the database it's srcuploadnameofimage.jpg
here is the upload button that i have
try {
String newpath = "src/upload";
File directory = new File(newpath);
if (!directory.exists()) {
directory.mkdirs();
}
File fileawal = null;
File fileakhir = null;
String ext = this.filename.substring(filename.lastIndexOf('.')+1);
fileawal = new File(filename);
System.out.println(newpath);
fileakhir = new File(newpath+"/"+Nik.getText()+"."+ext);
System.out.println(fileakhir);
stat = koneksi.createStatement();
stat.executeUpdate("insert into user values ('" + Nik.getText() + "','" + Nama.getText() + "','" + fileakhir.toString() + "')");
System.out.println(fileakhir.toString());
JOptionPane.showMessageDialog(null, "Akun Sudah Terdaftar, Silahkan Kembali Login");
Files.copy(fileawal.toPath(), fileakhir.toPath());
Login log = new Login();
log.setVisible(true);
this.setVisible(false);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
and this is the image picker button that i have
try {
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
ImageIcon icon = new ImageIcon(f.toString());
Image img = icon.getImage().getScaledInstance(Foto.getWidth(), Foto.getHeight(), Image.SCALE_DEFAULT);
ImageIcon ic = new ImageIcon(img);
Foto.setIcon(ic);
filename = f.getAbsolutePath();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
I have tried using .toString(), .getPath(), .getAbsolutePath(), but none of them include '/' in the database