This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem in updating values into database" Watch "Problem in updating values into database" New topic
Author

Problem in updating values into database

g anil kumar
Greenhorn

Joined: Jun 25, 2011
Posts: 5
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....
 
wood burning stoves
 
subject: Problem in updating values into database
 
Similar Threads
Jakarta FileUpload on local machine Tomcat
Problem with File Upload
fileupload upon tomcat on local machine
How to store a particular data into project file
how to upload pdf files to My sql with java