AntoniRyszard
asked on
Adding date to mysql tables?
Hello,
Using mysql I set a column datestamp to use the date field type.
Could anyone advise if I would use the java.sql.Date object to capture the time-clock to add this in the table?
And having stored the date, would I be-able to query the database datestamp field using a PreparedStatement to return fields with a particular month and year.
Or to query in this way would I need to have a separate, month and year field in the table?
Thank you
Using mysql I set a column datestamp to use the date field type.
Could anyone advise if I would use the java.sql.Date object to capture the time-clock to add this in the table?
And having stored the date, would I be-able to query the database datestamp field using a PreparedStatement to return fields with a particular month and year.
Or to query in this way would I need to have a separate, month and year field in the table?
Thank you
Yes, yes and no ;-)
Bear in mind that sql Date contains no hours, minutes etc.
ASKER
Thanks
Could I ask if this seems the correct way of returning the day, month, year.
Calendar calendar = new GregorianCalendar(2006, 0, 1);
java.sql.Date date = new java.sql.Date(calendar.get Time().get Time());
And to add the date in a preparedstatement, would I need to use date.toString()?
Could I ask if this seems the correct way of returning the day, month, year.
Calendar calendar = new GregorianCalendar(2006, 0, 1);
java.sql.Date date = new java.sql.Date(calendar.get
And to add the date in a preparedstatement, would I need to use date.toString()?
ASKER
Could I ask finally,
To return all the records with from march 06 and in ordered on the day. Could we achieve this from the datestamp field, which contains a java.sql.Data value?
To return all the records with from march 06 and in ordered on the day. Could we achieve this from the datestamp field, which contains a java.sql.Data value?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)