You could use a DateFormat object to transform the java.util.Date object
into a string that MSSQL will understand. Something like this (assuming
you want only the "date" part and not the time):
java.util.Date birthday = ...;
java.util.DateFormat cformat = new
java.util.SimpleDateFormat("dd-MMM-yyyy");
String statement = "insert into tablename (datecol) values ('" +
cformat.format(birthday) + "')"
Emmanuel Eze wrote:
>I get the error message when i use the prepared statement:
>[Microsoft][ODBC SQL Server Driver]Optional feature not implemented
>
>I am connecting to an MS SQL Server 2000 using JDBC-ODBC brige.
>
>-----Original Message-----
>From: Shi Zili [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, May 07, 2002 11:29 AM
>To: JDJList
>Subject: [jdjlist] Re: sql Date
>
>
>Use method prepareStatement of Class Connection to create statement instead
>of createStatement
>
> PreparedStatement pstmt = con.prepareStatement("INSERT INTO
>LOG(logtime,event) values (?,?)");
>
>
>>java.sql.Date sqlDate = new java.sql.Date(birthday.getTime());
>>
>>
> String message = ....;
>
>after you can pass sqlDate as parameter to the statement through method
>setDate
>
> pstmt.setDate(1, sqlDate );
> pstmt.setString(2, message );
>
>Now,
> pstmt.executeUpdate();
>
>to insert this record to table
>
>
>
>
>
>>java.sql.Date sqlDate = new java.sql.Date(birthday.getTime());
>>
>>and to pass it as parameter of the setDate(java.sql.Date) method
>>
>>----- Original Message -----
>>From: "Emmanuel Eze" <[EMAIL PROTECTED]>
>>To: "JDJList" <[EMAIL PROTECTED]>
>>Sent: Tuesday, May 07, 2002 11:03 AM
>>Subject: [jdjlist] sql Date
>>
>>
>>
>>
>>>Hi all,
>>>
>>>Can somebody pls tell me how I can insert a Date type into a database
>>>
>>>
>>table
>>
>>
>>>with a Date datatype?
>>>
>>>I have the year, month, and day as interger values. I need to convert
>>>
>>>
>>these
>>
>>
>>>values into an sql Date object so I can now insert the Date object into
>>>
>>>
>>the
>>
>>
>>>table, right?
>>>
>>>I have the folllowing code:
>>>Calendar cbirthday = null;
>>>java.util.sql birthday = null;
>>>.
>>>.
>>>.
>>>cbirthday = Calendar.getInstance();
>>>cbirthday.set(Integer.parseInt(year), Integer.parseInt(month),
>>>Integer.parseInt(day));
>>>birthday = cbirthday.getTime();
>>>
>>>This last statement throws a cast exception! Even when I chnage it to:
>>>birthday = (java.sql.Date) cbirthday.getTime();
>>>
>>>Pls tell me what I'm doing wrongly.
>>>
>>>Emma
>>>
>>>
>>>To change your membership options, refer to:
>>>http://www.sys-con.com/java/list.cfm
>>>
>>>
>>>
>>To change your membership options, refer to:
>>http://www.sys-con.com/java/list.cfm
>>
>>
>>
>>
>>
>
>
>
>To change your membership options, refer to:
>http://www.sys-con.com/java/list.cfm
>
>
>To change your membership options, refer to:
>http://www.sys-con.com/java/list.cfm
>
>
To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm