RE: DateTime format during INSERT using MS JDBC driver
From: Yilei Wang (yileiw_at_online.microsoft.com)
Date: 08/17/04
- Next message: Shelby Goerlitz [MSFT]: "Re: Microsoft JDBC and SSL Support"
- Previous message: Carb Simien [MSFT]: "Re: microsoft jdbc driver for SQL Server 7.0"
- In reply to: Tim: "DateTime format during INSERT using MS JDBC driver"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 17 Aug 2004 19:06:20 GMT
Hi Tim,
You can either use the parameterized query and pass in a value of a
Java.Sql.Date type. You can thus convert the "yyyy-mm-dd" string to Date.
Below is the code snippet:
PreparedStatement st = connection1.prepareStatement("INSERT
Customers (ArchiveDate) VALUES (?)");
st.setDate(1, Date.valueOf("1999-01-30"));
st.executeUpdate();
Or if you choose to hard code the "yyyy-mm-dd" in the query string, you can
use CONVERT function to convert the string to a datetime sql data type
according to the proper style of date format. 120 is the ODBC canonical
style that converts yyyy-mm-dd hh:mi:ss(24h). Below is the code snippet:
PreparedStatement st = connection1.prepareStatement("INSERT
Customers (ArchiveDate) VALUES (CONVERT (datetime, '1999-01-30', 120) )");
st.executeUpdate();
For more info on CONVERT, please refer to the SQL Server Books Online.
Yilei
- Next message: Shelby Goerlitz [MSFT]: "Re: Microsoft JDBC and SSL Support"
- Previous message: Carb Simien [MSFT]: "Re: microsoft jdbc driver for SQL Server 7.0"
- In reply to: Tim: "DateTime format during INSERT using MS JDBC driver"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|