July 11th, 2003, 12:44 PM
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 + "')";
July 13th, 2003, 11:19 PM
If you want YYYY-MM-DD then you could use this.
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date oradate = dateFormat.parse(dateToSave);
July 14th, 2003, 04:19 AM
java.util.Date now = new java.util.Date();
java.sql.Date sqlNow = new java.sql.Date(now.getTime());
String sqlStringDate = sqlNow.toString();