Hi,
I have created a file upload. Work, but I save the file in the first time in
a temporary folder and after into DB...but I want save the file only in my
DB.
Do you have any suggestion?
This is my code:
********************************************************
DiskFileUpload dfu = new DiskFileUpload();
try {
List fileItems = dfu.parseRequest(req);
Iterator it = fileItems.iterator ();
while (it.hasNext()) {
FileItem f = (FileItem) it.next();
File file=new File(getServletContext().getRealPath("/"), f.getName
());
f.write(file);
out.println ("File " + f.getName() + " saved in "
+ file.getAbsolutePath() + "<BR>");
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection
("jdbc:mysql://localhost/test",
"root", "root");
PreparedStatement ps = conn.prepareStatement("insert into immagini
values(null, ?)");
FileInputStream fis = new FileInputStream(file);
ps.setBinaryStream(1, fis, (int)file.length());
ps.executeUpdate();
ps.close();
conn.close();
}
} catch (Exception e) { ...}
********************************************************