To Upload and insert the file into Database with Current Date and Time In JSP

Advertisement

In this section, you will learn how to insert data and upload file using in jsp.

To Upload and insert the file into Database with Current Date and Time In JSP

In this tutorial, you will learn how to upload a file through JSP and
insert it into the database. For this, we have created two jsp pages page.jsp and upload_page.jsp.
The page.jsp is created for presentation where a file component is
created to let the user select the file to be uploaded and a button to submit
the request. The action is performed on upload_page.jsp. Before
proceeding further, we need table in database. We created table named 'file' for
our example.

This file upload and insert into database with current
date and time using JDBC database. This can be done

(i).To import
java.io.*,java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat
packages. Java.io Packages is used to read and write the file
uploaded having classes like DataInputStream, FileOutputStream etc. java.util.*,java.text.*,java.text.SimpleDateFormat
is used to retireve the current Date and Time.
(ii). Prepared Statement is used to insert the data into database having used
pstatement=con.prepareStatement(queryString);
(iii). Using a Query "INSERT INTO file_tbl set
file_data='"+value+"',file_date='"+strDateNew+"'" to
insert the data into database.

Step 4: Output when file upload and insert into database with current date
and time.

siddhi
September 12, 2011
Upload files with any extension to the database
Hello frds, Can neone help me with how to upload the files with different extensions in the database.,and then later on retrieving datfile back from the database...PLz Plz

dhanavanthini
November 9, 2011
sql query
i want to upload a file into database but i cant use the'text' datatype while creating table,whether i can use the 'varchar' datatype to upload file?

stephen
December 21, 2011
file not seen in my database
I came across your upload tutorial and I followed the direction and installed the download script from your website, perhaps, the upload file shows successful but I can not see the file in my database.
What should I do so that when it shows file successful, I should be able to see it in my database?

kiran
February 29, 2012
unable to execute
iam trying this code with ms access database connection getting an exception while uploading.......
org.apache.jasper.JasperException: /jsp/eshoppe/upload_page.jsp(0,60) equal symbol expected
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:94)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:428)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:126)
at org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:169)
at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:136)
at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:149)
at org.apache.jasper.compiler.ParserController.figureOutJspDocument(ParserController.java:254)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:173)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:153)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:227)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:369)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2417)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:193)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:549)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Thread.java:619)