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 12:23:26 GMT
Thanks :)
I have seen that DiskFileUpload is a deprecated class, so I have edit my
source...now work well :D
What do you thinks? In your opinion is correct?

............................................................................................................
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List /* FileItem */ items = upload.parseRequest(req);

Iterator iter = items.iterator();
while (iter.hasNext()) {
     Class.forName("com.mysql.jdbc.Driver");
     FileItem item = (FileItem) iter.next();

     Connection conn = DriverManager.getConnection("jdbc:mysql://localhost
/test","root", "root");
     PreparedStatement ps = conn.prepareStatement("insert into
immaginivalues(null, ?)");


     InputStream uploadedStream = item.getInputStream();
     ps.setBinaryStream(1, uploadedStream, (int)item.getSize());

     ps.executeUpdate();
     ps.close();
     conn.close();
}

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