#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    New York City
    Posts
    83
    Rep Power
    12

    setting a Date field in MySQL, using JSP


    Okay guys, here's my problem:

    All I want to do is pull the current system date in the process.jsp, using possibly the SimpleDateFormat (??) object. Then, I need to set the year, month, and day into the Date field of the generated results in the format of: yyyy:mm:dd (it should be a String). I am not sure which date object can generate the current date in this format.

    The query code I'm using is as follows:

    String insertString = "INSERT INTO purchase_order_tbl VALUES (" + null + ", " + Integer.parseInt(id) +
    ", " + /* INSERT DATE HERE (yyyy:mm:dd) */ + ", " + null + ", " + null + ", " + null + ", '" + vendor + "', '" + email + "', '" + address + "', '" + phone + "', '" + name + "')";
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    No es importante
    Posts
    2,065
    Rep Power
    14
    If you want YYYY-MM-DD then you could use this.
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date oradate = dateFormat.parse(dateToSave);
  4. #3
  5. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
    Alternatively:
    Code:
    java.util.Date now = new java.util.Date();
    
    java.sql.Date sqlNow = new java.sql.Date(now.getTime());
    
    String sqlStringDate = sqlNow.toString();
    ~ishnid

IMN logo majestic logo threadwatch logo seochat tools logo