I am basically trying to convert a string similar to this one: "2011-11-9 18:24:12.3
" into a format that I can insert into a database table claiming this particular column to be of the "datetime" type. I figured I could do something along the lines of preparedStatement.setTimestamp(...)
, but I can't seem to get a Timestamp created correctly. Can anyone suggest the easiest way to convert a string like the one above to either a Timestamp or some other type which is compatible with MySQL's "datetime" type? Any help would be appreciated.
Thus far, I've tried doing something like this:
String strDateTime = "2011-11-9 18:24:12.3";
Timestamp timeStamp = new Timestamp((new Date(strDateTime)).getTime());
preparedStatement.setTimestamp(1, timeStamp);