Home > Java, MSSQL > Insert Java Date type into MSSQL’s datetime

Insert Java Date type into MSSQL’s datetime

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
{
}

Categories: Java, MSSQL Tags:
  1. No comments yet.
  1. No trackbacks yet.