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);

```
['https://Stackoverflow.com/questions/8074168', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/967968/']
Ah, so, the problem is most likely not with the datetime of mysql but with the date.

The `Date(Strings s)` constructor is [currently deprecated](http://download.oracle.com/javase/6/docs/api/java/util/Date.html#Date%28java.lang.String%29) and is recommended to use a [SimpleDateFormat](http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html) which would let you use any format you want.
Have you tried splitting and making it into a format you can use? This assumes that this is in the same format all the time. Create a new string that takes apart a split of the old string and rearranges it in a useful way. If this is a string provided by the end-user, you may have to validate it first and check to make sure it is usable.