pls,i need help in inserting a date from a text field using java, to mssql database.
i am getting incorrect date for example when i insert 13/3/2010,i am getting the date
1/3/2011.i want a solution,i've searched a lot but useless.
the code is:
try{
java.util.Date d;
String s;
d = new java.util.Date(t.getText().trim());
SimpleDateFormat df =new SimpleDateFormat("MM/dd/yyyy");
s=df.format(d);
System.out.println(s);
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection ("jdbc:sqlserver://localhost:1433;DatabaseName=employee;user=sa;password=moujtaba");
Statement insert=conn.createStatement();
insert.executeUpdate("insert into constructionmaterial(inward,date,reference) values (15,'" + s + "',1)");
}catch(ClassNotFoundException cnfe)
{
System.err.println(cnfe);
}
catch (SQLException sqle)
{
System.err.println(sqle);
}
}