string. Hi guys! I am using SQLSERVER 2005+jdk1.6 Where i am sending date as a String and typcasted to date format by Simpledateformat .while inserting in database its giving error" //error is Conversion failed when converting datetime from character " Here the code:: SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); dt = formatter.parse(login_form.getDate()); // date = login_form.getDate();
Originally posted by Amit Ghorpade: Hi, I have not used SQLSERVER, but I think that most databases accept date in mm/dd/yyyy format.
Hope this helps
I think it depends on the regional settings, but I always just use yyyy-MM-dd to make sure. That format never gets interpreted incorrectly.
Another good idea is of course to use PreparedStatement, and use the setDate or setTimestamp methods. You'll need to convert a java.util.Date object to a java.sql.Date or java.sql.Timestamp object for that, but that's easy: