Insert Java Date type into MSSQL’s datetime
May 17th, 2007
No comments
Seems a little ugly for what it does, but hey it’s OO-fantastic.
Statement stmt = null;
Connection con = null;
try
{
Class.forName(“com.microsoft.sqlserver.jdbc.SQLServerDriver”);
con = DriverManager.getConnection(connectionURL);
stmt=con.createStatement();
java.text.DateFormat df = new java.text.SimpleDateFormat(“MM/dd/yyyy”);
String startDate = df.format(date_var);
stmt.executeUpdate(“INSERT INTO XX (day_entry) VALUES (‘” + startDate + “‘);”);
}
catch(Exception e)
{
System.out.println(query);
e.printStackTrace();
}
finally
{
}