Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.io.FileNotFoundException after uploading a file

843838Aug 11 2006 — edited Aug 12 2006
Hi developers, i got this java.io.FileNotFoundException after i attempt upload a file to my database? what could be the problem here? I'm using jsp, struts, db2, ibm rad6 for developing. Below is my action class.java file

****StrutsUploadAction.java****

import java.io.*;
import java.sql.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

public class StrutsUploadAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{

StrutsUploadForm myForm = (StrutsUploadForm)form;

// Process the FormFile
FormFile myFile = myForm.getTheFile();
String contentType = myFile.getContentType();
String fileName = myFile.getFileName();
int fileSize = myFile.getFileSize();
byte[] fileData = myFile.getFileData();
InputStream strem = myFile.getInputStream();

try
{ // Prepare a Statement:
ConnectDB cn = new ConnectDB();
cn.init();
java.sql.Connection con = cn.connectdb();
PreparedStatement stmt = con.prepareStatement("INSERT INTO ADMINISTRATOR.TESTFILEUPLOAD (FILENAME) values(?)");

File file = new File(fileName);
FileInputStream inputStream = new FileInputStream(file);
stmt.setBinaryStream(1,inputStream,(int)(file.length()));
stmt.executeUpdate();


// Close resources
stmt.close();


}
catch(Exception ex)
{
System.out.println("Error occurred writing a BLOB: " + ex);
}
return mapping.findForward("success");
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 9 2006
Added on Aug 11 2006
4 comments
568 views