Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet jsp & serlvet
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


blackcurren
jsp & serlvet
1 Answer(s)      a year ago
Posted in : JSP-Servlet


hi, may i know how to insert datetime into mysql database upon clicking a button in jsp page? preferably using the mvc method. thanks in advance. :)


Advertisement
View Answers

December 11, 2013 at 2:02 PM


Hi I can help you.

step1: first create the table with date column. ex: datetable with todaydate column. step2: create the jsp with date field (date.jsp)

   <form action="./dateServlet" >
       Date: <input type="text" name=" fieldDate" value="dd/mm/yyyy" />  
       <br>
       <input type="submit" value="store" />
  </form>

step3: create the servlet like DateServlet.java

  public class DateServlet extends HttpServlet {

    public void service(HttpServetRequest request,HttpServletResponse response) {


        String fieldDate=request.getParameter      

                                 ("fieldDate");

         SimpleDateFormat  sf=new SimpleDateFormat("dd/mm//yyyy");

          java.util.Date d=sf.format(filedDate);

           DateDAO dao=new DateDAO();
           dao.store(d);

    }
  }
  configure this servlet in web.xml with /dateServlet

step 4: create the dao class to store the date in datetable.

public class DateDAO{
     public void store(java.util.Date d) {
        java.sql.Date date=new java.sql.Date(d);

        Class.forName("oracle.jdbc.driver.OracleDriver");
      Connection con=DriverManager.getConnection(url,username,password);

     PreparedStatement ps=con.prepareStatement("insert into datetable values(?)");

    ps.setDate(1,date);

    ps.executeUpdate();
    ps.close();
    con.close();

     }
}


Related Tutorials/Questions & Answers:
jsp & serlvet
jsp & serlvet  hi, may i know how to insert datetime into mysql database upon clicking a button in jsp page? preferably using the mvc method. thanks in advance
why business logic in servlets - JSP-Interview Questions
why business logic in servlets  why business logic written using servlets not in jsp. Jsp used for presentation purpose. serlvet used for coding business logic and controller logic. Reason for using servlets in business logic
Advertisements
jsp
jsp  how to include two jsp page
JSP
what is JSP forward tag for  what is JSP forward tag for   It forwards the current request to another JSP page. Below is the syntax for the same:- <jsp:forward page="...url..." /> We can also forward parameter
Jsp
Jsp  Can I implement interface in jsp
jsp
jsp  how to create jsp page
JSP
JSP  How to run jsp program in eclipse
jsp
jsp  how jsp translated into servlets
jsp
jsp  write a code for jsp file generator to generate a jsp page automatically taking html page as input
jsp
jsp  how to create a table in oracle using jsp and the table name is entered in text feild of jsp page
JSP
JSP  Hi, What is JSP? What is the use of JSP? Thanks   Hi, JSP Stands for Java Server Pages. It is Java technology for developing web applications. JSP is very easy to learn and it allows the developers to use Java
jsp
jsp   what is the basic necessities reguired for running jsp using JDBC bridge?? and how to write a jsp code to access the detail present in microsoft access pls send link regarding above
jsp
jsp  how to connect the database with jsp using mysql   Hi Friend, Please visit the following links: http://www.roseindia.net/jsp/connectjspwith_mysql.shtml http://www.roseindia.net/jsp/Accessingdatabase-fromJSP.shtml
jsp
jsp  how to upload image through csv format in jsp
jsp
jsp  I Want complete note on JSP servlet
jsp
jsp  how to delete data from database using jsp
JSP
JSP  FILE UPLOAD-DOWNLOAD code USING JSP
jsp
jsp  how to write hindi in jsp and store in database as unicode
jsp
jsp  code for jsp automatic genration using html
jsp
jsp  why jsp is translated into servlet?pls describe precisly
JSP
JSP  relevant difference between servlet and jsp in 1 line
jsp
jsp  how to pass jsp variable to an html page
jsp
jsp  how to write a servlet and jsp program for user login form
jsp
jsp  how to write a servlet and jsp program for user login form
JSP
JSP   How to create CAPTCHA creation by using JSP? I need an code for CAPTCHA creation by using JSP...   You can create a captcha validation using jsp. Have a look at the following tutorial: Captcha Creation
jsp
jsp  how to include google map in our jsp page
JSP
What are JSP directives, page directives and include directives?  what are jsp directives? and what are page directives? and what are include directives? can you explain taglib directives?   JSP directives JSP
JSP
Can you explain jsp page life cycle what is el how does el search for an attribute in JSP  Can you explain jsp page life cycle what is el how does el...://www.roseindia.net/jsp/simple-jsp-example/LifeCycleOfJspPage.shtml http
JSP
JSP  what are the different scopes an object can have in a jsp page   JSP Scope Variables: Page scope-It makes the data available... the following links: http://www.roseindia.net/jsp/simple-jsp-example
JSP
what is jstl in JSP   what is jstl   JSTL is also called as JSP tag libraries. They are collection of custom actions which canbe accessed as JSP tags. For more information, visit the following link: JSTL Tutorials
JSP
access application data stored in JavaBeans components. The jsp expression...). Before JSP 2.0, we could use only a scriptlet, JSP expression, or a custom tag to include server state in the jsp page output. For more information, visit
 

 

 

DMCA.com