DiskFileUpload dfu = new DiskFileUpload();
try {
List fileItems = dfu.parseRequest(req);
Iterator it = fileItems.iterator();
while (it.hasNext()) {
FileItem f = (FileItem) it.next();
//the code down here means create a file on the path you gave,if u
don't want,just delete it
//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");
//but i am not sure about the code you write here
//does it work insert the bytes into you DB?
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();
}
2008/1/22, Matteo Di Palma <[EMAIL PROTECTED]>:
>
> 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
>
--
Lilei
Software Development Group, Computer Center
BYD Company Limited
No.3001, Hengping Road, Pingshan, Longgang, Shenzhen, 518118, P.R.China
Tel: +86-755-89888888
Fax: +86-755-84202222