problem in formatting date

jen plecerda

Greenhorn

Posts: 4

posted 9 years ago

hi! i have a string in this kind of format and i need to store it in mysql database..IGMTCCBNO12/1/2006

i established a connection to the database and inserted the value but when it comes to date, the value inserted in the mysql was this value: 0000-00-00. i was expecting it should be like this:2006-01-12.. any suggestion in my program is much appreciated!

I see you have 5 colums in your table, but you only insert 4 values. Maybe this will give you an error(just look at the stacktrace that you print)

I agree with Jesper that it's better(faster, more secure, easier to read) to use Preparedstatement instead of Statement.

Note that in case of an Exception, your statement and connection will not get closed. They will always get closed, if you just put them in a finally{} block.

Herman

jen plecerda

Greenhorn

Posts: 4

posted 9 years ago

hi guys!

after doing the prepared statement that mr. ricky martaputra suggested in my first post: problem with storing date now i realized and agree to mr jesper and herman that using prepared statement is much better instead of using statement. don't wory guys my program is now working!hehehe...