【转贴】Insert Java Date type into MSSQL’s datetime

转自:
http://iraniweb.com/blog2/?p=5

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

posted @ 2008-02-02 15:12  N/A2011  阅读(474)  评论(0)    收藏  举报