File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Problem in updating values into database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem in updating values into database" Watch "Problem in updating values into database" New topic

Problem in updating values into database

g anil kumar

Joined: Jun 25, 2011
Posts: 5
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 language="java" %>

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


<%@ page import="*" %>
<%@ 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

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

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

//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());
File tempFileRef = new File(fi.getName());

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

//"C:\\Tomcat 5.5\\webapps\\start2finish\\ImageUploads"

if (fi.getName() != "") {
File fNew= new File("C:\\anil",tempFileRef.getName());
else {
name =fi.getFieldName();
String value=fi.getString();
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....
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Problem in updating values into database
It's not a secret anymore!