You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Joe Shevland <sh...@kpi.com.au> on 2000/07/27 08:36:04 UTC

RE: SQL statement

>-----Original Message-----
>From: Darren Lee Deliang [mailto:just_darren@hotmail.com]
>Sent: Friday, 28 July 2000 12:24 AM
>To: tomcat-user@jakarta.apache.org
>Subject: SQL statement
>
>
>Hi guys see if you can help me out on this:
>

You're certainly pushing the envelope of this list's charter ;)


>i need to extract only certain rows from a database based on the month and 
>year selected by the user compared against a value in the database called 
>startdate. is it like that?
>
>//======================================================================
>
>Part of the codes (Prepared Statement)
>
>"SELECT * FROM ApplicationRecord WHERE MONTH(startDate) = ? AND 
>YEAR(startDate) = ?"
>
>st.setString(1, month);
>st.setString(2, year);

It'd probably be:

st.setInt(1, month) etc.

>
>//======================================================================
>
>Wat is the exact syntax for extracting the month or year value of a 
>timestamp object from an database (SQL Server)?

A column of type timestamp (contrary to intuition) does not store the exact date and time (in a decent format); a datetime field should be used for this, and then just use Month() etc. to retrieve values from the datetime. You can also use CONVERT(date,fmt) to get various date formats back.

Timestamp is more a binary thing (the only reason I've used one is for cases where I need Access to behave itself when linked to a remote SQL Server).

Joe

>________________________________________________________________________
>Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>
>