Date

I read from plain text and i got "Tue Nov 23 15:11:44 1999" string. How could i store it in my database that has table with a Date/Time field ?
ImeldaAsked:
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.

GregLCommented:
PreparedStatement.setDate
public void setDate(int parameterIndex,
                    Date x)
             throws SQLException Sets the designated parameter to a value. The driver converts this to an SQL DATE value when it sends it to the database. Parameters:parameterIndex - the first parameter is 1, the second is 2, ...x - the parameter valueThrows:SQLException - if a database access error occurs
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
Ravindra76Commented:
Hi GredL,

 Before setting date in preparedStatement , it should be in yyyy-mm-dd format.

How will you convert

Tue Nov 23 15:11:44 1999

to

1999-11-23

Thank you
0
jsridharCommented:
   SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy");
    ParsePosition pos = new ParsePosition(0);
    java.util.Date dte = sdf.parse("Tue Nov 23 15:11:44 1999", pos);

can be used for parsing the date from String object to Date object.

js.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

GregLCommented:
You don't need to.  You just pass the Date() object.
0
ImeldaAuthor Commented:
I must use java.util.Date or java.sql.Date ? Beside that, how to change "Tue Nov 23 15:11:44 1999" into format "yyyy-mm-dd" ?
My friend tell me I can pass string into date field in the table. It will convert automatically. Is that true ?
0
jsridharCommented:
This is answered in your query on "Date II"

js.
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

From novice to tech pro — start learning today.