Unable to upload a file to mysql database using struts1
Hi,
Below are my classes
1.upload.jsp
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<html:html>
<body>
<html:form action="upload" enctype="multipart/form-data">
Select a File :<html:file property="file"/>
<html:submit/>
</html:form>
</body>
</html:html>
2.UploadForm.java
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
public class UploadForm extends ActionForm{
private FormFile file;
public FormFile getFile(){
return this.file;
}
public void setFile(FormFile file){
this.file=file;
}
}
3.UploadAction.java
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.sql.*;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
public class UploadAction extends Action{
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
UploadForm uploadForm=(UploadForm)form;
System.out.print("Executed");
FormFile formFile=uploadForm.getFile();
System.out.print("Executed1");
String fileName=formFile.getFileName();
System.out.print(fileName);
File file=new File(fileName);
System.out.print(">>>>");
FileInputStream fin=new FileInputStream(file);
System.out.print("*****");
Integer fileSize=formFile.getFileSize();
int insert=0;
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver Loaded.");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
System.out.println("Connection Opened.");
PreparedStatement pst=con.prepareStatement("insert into upload values(?)");
pst.setBinaryStream(1,fin,fileSize);
insert=pst.executeUpdate();
System.out.print("File Uploaded.");
}
catch(Exception e){System.out.println(e);}
if(insert!=0){
return mapping.findForward("success");
}
else{
return mapping.findForward("error");
}
}
}
I am getting error in this line * FileInputStream fin=new FileInputStream(file);* in the above action class i.e UploadAction.java
And below is the error I am getting in tomcat ...
exception
java.io.FileNotFoundException: ZensarCVFormat.doc (The system cannot find the file specified)
java.io.FileInputStream.open(Native Method)
java.io.FileInputStream.(Unknown Source)
UploadAction.execute(UploadAction.java:19)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
Please Help me how to resolve this issue...
Kindly reply back ASAP...
Thanks in advance...
View Answers
Ads
Related Tutorials/Questions & Answers:
Image upload in mysql database using jsp servlet
Image
upload in
mysql database using jsp servlet Hello, I need code to insert image in
mysql database, I have seen the code which is already in your... different format of
file to
upload into
mysql db like pdf and doc
file
Advertisements
file upload using JSP
file upload using JSP I have created a form to
upload a
file...="java" %>
<HTML>
<HEAD><TITLE>Display
file upload form... To
Upload:</b></td>
<td><INPUT NAME="
file" TYPE="
file"><
upload csv to mysql db using jsp upload
upload csv to
mysql db
using jsp upload Hello all,
Please give me the code to uplad .csv from jsp page and insert values into
MySQl db. I have a table with 8 cloumns.(MDN--varchar(30),Otafdate date,crt varchar(30),dmdn
database connectivity using mysql
database connectivity
using mysql java
file: eg1.java
package eg... seconds)
I am
using Netbeans 5.5,
mysql server 5.0, to get data from table...[]) throws SQLException
{
try
{
String connectionURL = "jdbc:
mysql
PHP code for csv file upload into mysql
PHP code for csv
file upload into mysql I want to
upload a
file from my pc to
mysql server
using upload option. while i m selecting the csv
file it ll be
upload the
mysql database. can u send me the coding?
i have tried
How to upload file using JSP?
How to
upload file using JSP? Hi all,
I m the beginner in JSP, I want to
upload file on server in specific folder.
1)page.jsp...
file upload form to the user</TITLE></HEAD>
<
form based file upload using servlets
form based
file upload using servlets Hai all,
I wrote a program to
upload a
file into specified directory and store the
file path and username...
file path
it uploaded successfully
but in
database table it gives null value
File Upload
File Upload when i execute the image
upload to
mysql database it shows an exception that
file path cannot be found
To Upload and insert the CSV file into Database
To
Upload and insert the CSV
file into
Database... to
upload a CSV
file through JSP and
insert it into the
database. For this, we have... on
upload_page.jsp. Before
proceeding further, we need table in
database. We created
upload a file and write it in JSP using servlet
upload a
file and write it in JSP
using servlet Hello, I'm facing a problem here. I want to
upload a
file through abc.jsp and write the contents of
file using a servlet in xyz.jsp. It is supposed to be a excel
file which
downloading a file directly from mysql using java
downloading a
file directly from
mysql using java Hi, I am trying to come up with a code to download a
file that is on a
mysql database (in form of a blob) without
using url. Can anyone tell me how it can be done because I am