Chris is absolutely right.  As in many other cases, using a
PreparedStatement handles a lot of things that could otherwise end up in a
syntax mess.

    Still, there is a standard syntax to express dates in a regular
Statement..  If you're interested, see

"What is the JDBC syntax for using a date literal or variable in a standard
Statement?"

http://www.jguru.com/faq/view.jsp?EID=507218

HTH,


                                                         Joe Sam

Joe Sam Shirah -        http://www.conceptgo.com
conceptGO         -        Consulting/Development/Outsourcing
Java Filter Forum:       http://www.ibm.com/developerworks/java/
Just the JDBC FAQs: http://www.jguru.com/faq/JDBC
Going International?    http://www.jguru.com/faq/I18N
Que Java400?             http://www.jguru.com/faq/Java400


----- Original Message -----
From: "Chris Pratt" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, September 09, 2003 9:44 PM
Subject: Re: Date in a query Statement


> The best option would be to use a prepared statement like this:
>
>         PreparedStatement pst = con.prepareStatement("SELECT
> code,fname,lname FROM employee WHERE datestarted = ?");
>         try {
>           pst.setDate(1,datestarted);
>           ResultSet res = pst.executeQuery();
>           try {
>             while(res.next()) {
> //              Do something with the Results
>             }
>           } finally {
>             res.close();
>           }
>         } finally {
>           pst.close();
>         }
>
>   (*Chris*)
>
> ----- Original Message -----
> From: "Rasoul Hajikhani" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, September 09, 2003 4:45 PM
> Subject: [SERVLET-INTEREST] Date in a query Statement
>
>
> > Hello,
> > I have the following sql statement:
> >
> > SELECT code,fname,lname FROM employee WHERE datestarted = '02/12/2001'
> >
> > This works fine when executed through dbaccess, but when I use JDBC to
get
> a
> > ResultSet nothing is returned.
> > I am using  JDBC.2.21.JC5, my back end eis is Informix Universal server.
> > Also, the query executes fine when I remove the date part:
> >
> > SELECT code,fname,lname FROM employee
> >
> > Can any one tell me what am I doing wrong since I am new to JDBC.
> >
> > Thanks in advance.
> > -r
> >
> >

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to