• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Problem in updating values into database

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
i want to upload a file and at the same time i need the field values and to update the file path and the name field to br updated into database.
I'm using apache commons file uploading
this is the program for file uploading
Page.jsp
<%@ page language="java" %>
<HTml>
<HEAD></HEAD>

<BODY> <FORM ENCTYPE="multipart/form-data" ACTION="uploadbyapache1.jsp" METHOD=POST>
<br><br><br>
<center>
<table border="0" bgcolor=#ccFDDEE>
<tr>
<center>
<td colspan="2" align="center"><B>UPLOAD THE FILE</B><center></td>
</tr>
<tr>
<td colspan="2" align="center"> </td>
</tr>
<tr>
<td><b>Choose the file To Upload:</b></td>
<td><INPUT NAME="filename" TYPE="file"></td>
</tr>
Name<INPUT NAME="name" TYPE="text"></td>
<tr>
<td colspan="2" align="center"> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit"> </td>
</tr>
<table>
</center>
</FORM>
</BODY>
</HTML>


uploadbyapache1.jsp

<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
<%@ page import="org.apache.commons.fileupload.*" %>
<%
String name;
System.out.println("Content Type ="+request.getContentType());

DiskFileUpload fu = new DiskFileUpload();
// If file size exceeds, a FileUploadException will be thrown
fu.setSizeMax(-1);

List fileItems = fu.parseRequest(request);
Iterator itr = fileItems.iterator();

while(itr.hasNext()) {
FileItem fi = (FileItem)itr.next();


//Check if not form field so as to only handle the file inputs
//else condition handles the submit button input
if(!fi.isFormField()) {


System.out.println("\nNAME: "+fi.getName());
System.out.println("SIZE: "+fi.getSize());
//System.out.println(fi.getOutputStream().toString());
File tempFileRef = new File(fi.getName());

//Create a new directory
File testDir = new File("C:\\anil");
if ( !testDir.exists() ){
testDir.mkdirs();
}

//application.getRealPath("/")
//"C:\\Tomcat 5.5\\webapps\\start2finish\\ImageUploads"

if (fi.getName() != "") {
File fNew= new File("C:\\anil",tempFileRef.getName());
out.println(fNew.getAbsolutePath());
fi.write(fNew);
}
}
else {
name =fi.getFieldName();
String value=fi.getString();
if(name.equals("name"))
{
name=value;
//out.println(name);
}
out.println(name+"this is outside block");
out.println("Field ="+fi.getFieldName());
%>
this is texts<input name="name" type="text" value="<%=name%>">
<%
}
}
%>

I'm able to upload the file and also i got the field value by not able to understand how to update the filepath and the name into the database..
Please some one help me out...
Thank you....
 
reply
    Bookmark Topic Watch Topic
  • New Topic