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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
GregLConnect With a Mentor Commented:
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
All Courses

From novice to tech pro — start learning today.