Store Java date and time in MySQL

How do I store a date and time in MySQL using java servlets?
First I create current date/time:
            Calendar cal = Calendar.getInstance();
            Date now = cal.getTime();
This is correct. I can output correct date and time:
            SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");
                System.out.println(sdf.format(now));
gives correct date and time.
In prepared statement I use:
                  pstmt.setDate(5, new java.sql.Date(ticket.getCreationDate().getTime()));
When I check the table, it has only stored the date: 2010-04-06 00:00:00
The MySQL datatype is DATETIME.
I do not want to store it as a string, because I want to sort by date when retrieving the data.
LVL 5
wolfje_xpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ksivananthCommented:
use DATETIME datatype in MySQL and use
pstmt.setTimestamp( new Timestamp( ticket.getCreationDate().getTime() ) ) ;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wolfje_xpAuthor Commented:
Thank you very much!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.