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
Related Tutorials/Questions & Answers:
Image upload in mysql database using jsp servletImage
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 JSPfile 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 uploadupload 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
PHP code for csv file upload into mysqlPHP 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>
<
database connectivity using mysqldatabase 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 form based file upload using servletsform 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 UploadFile Upload when i execute the image
upload to
mysql database it shows an exception that
file path cannot be found
using a database to upload items - Java Beginnersusing a
database to
upload items I need to create a
database to
upload item codes so that when i input the item code is displays on the screen. here is my code and the items i need in a
database
import javax.swing.*;
import
upload a file and write it in JSP using servletupload 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
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
downloading a file directly from mysql using javadownloading 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
Import Excel file(date) into mysql database in phpImport Excel
file(date) into
mysql database in php I try to import excel
file which contains data date(yyyy-mm-dd) into
mysql database in php...();
//connect to the
database
$connect =
mysql_connect("localhost","root","");
mysql unable to connect database in javaunable to connect
database in java Hello Everyone! i was trying to connect
database with my application by
using java but i am
unable to connect...
i was
using this code....
try
{
Driver d=(Driver)Class.forName
Using MYSQL Database with JSP & Servlets.
Using MYSQL Database with JSP & Servlets.
... acceres the
MYSQL
database. Here I am
using MYSQL & tomcat server... server
from www.mysql.com.
Upload the
downloaded
file login page using jsp servlrt with mysql database?login page
using jsp servlrt with
mysql database? Description:
example:total users are 3.each use have username and password save in
mysql database table login.
After successfully login
user1 see only index page,if user2 login
File Upload and Retrive filesFile Upload and Retrive files Can any body help me am getting an error in uploading
file. into
mysql database....
thank's in advance
upload image to databaseupload image to database i am try to
upload image to
MySql database using netbeans.
when jsp execute it return no error. but also data does inserted in
database. i am
using blob datatype and preopared statement