commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Matteo Di Palma" <dipalma.mat...@gmail.com>
Subject Re: How save a file into DB
Date Tue, 22 Jan 2008 11:43:42 GMT
Can you give me an example please?
Can you tell me EXACTLY what lines should change the following code?
There are days that I try uselessly : (
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();
}
............................................................................................
Very very thanks,
Matteo

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message