Results 1 to 2 of 2
  1. #1
    KumbhaniMehul is offline Member
    Join Date
    Apr 2010
    Posts
    16
    Rep Power
    0

    Default storing date from servlet to sql server

    i just want to store date from my servlet to sql server table in the following formate 10/04/2010

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    so the problem is reading the user's form input string in this format into the Date database property ?

    e.g.
    Java Code:
    String formFieldDateValue = request.getParameter("myDate");
    new SimpleDateFormat dateFormat("dd/MM/yyyy");
    Date myDate = null;
    try {
      myDate = dateFormat.parse(formFieldDateValue);
    }
    catch (ParseException ex) {
      // this is where we handle the invalid date entered, 
    }
    
    // and later on, in the jdbc insert part
    // assuming you are using prepared statements to insert
    Connection con = null;
    PreparedStatement stmt = null;
    try {
      con = // how ever you get the connection, e.g. data sourece
      stmt = con.prepareStatement("insert into my_table(date_value) values (?);
      stmt.setDate(1, myDate);
      stmt.executeUpdate();
    }
    catch (SQLException ex) {
      // handle database errors here
    }
    finally {
      //close statement and connection.
    }

Similar Threads

  1. Replies: 1
    Last Post: 12-02-2008, 12:23 AM
  2. Compare date input to database with current date
    By hungleon88 in forum Advanced Java
    Replies: 2
    Last Post: 11-25-2008, 08:10 AM
  3. Run servlet in HTTP server
    By jithan in forum New To Java
    Replies: 25
    Last Post: 10-16-2008, 10:10 AM
  4. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 08:32 PM
  5. Date/Time Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-14-2008, 09:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •