khaled_jawaher -2 Junior Poster in Training

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 problem is in mssql not java,so what i can do to configure date to accept dd\MM\yyyy
the code is:

Java Syntax (Toggle Plain Text)

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);                }           } 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); 
               }  
         }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.