Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 45062 invoked from network); 4 Feb 2009 18:35:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Feb 2009 18:35:04 -0000 Received: (qmail 67851 invoked by uid 500); 4 Feb 2009 18:35:02 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 67831 invoked by uid 500); 4 Feb 2009 18:35:02 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 67822 invoked by uid 99); 4 Feb 2009 18:35:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Feb 2009 10:35:02 -0800 X-ASF-Spam-Status: No, hits=2.7 required=10.0 tests=MSGID_FROM_MTA_HEADER,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: 83.137.146.145 is neither permitted nor denied by domain of stephan@republika.nl) Received: from [83.137.146.145] (HELO mail.republika.nl) (83.137.146.145) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Feb 2009 18:34:53 +0000 Message-ID: <529211275.62081233772472744.JavaMail.james@republika.nl> MIME-Version: 1.0 X-UserIsAuth: true X-MessageIsInfected: false Received: from 5ED40BEC.cable.ziggo.nl. ([94.212.11.236]) by mail.republika.nl (REPUBLiKA SMTP Server 1.0) with ESMTPA ID 656 for ; Wed, 4 Feb 2009 19:34:32 +0100 (CET) Date: Wed, 04 Feb 2009 19:34:32 +0100 From: "Stephan van Loendersloot (LIST)" Organization: REPUBLiKA B.V. User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) To: Derby Discussion Subject: Re: Derby/Oracle - single SQL query? References: <032D6760-74DE-4AB7-B033-11E16CCB9473@iotabits.com> <4989DB49.6000702@sbcglobal.net> In-Reply-To: <4989DB49.6000702@sbcglobal.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Kathey Marsden wrote: > Kent Spaulding wrote: >> >> Is there some query format that will for both? > I don't have access to Oracle, but would it work to use an explicit cast > and cast(d.insertion_date as date) <= CAST('2009-02-28' AS DATE); > > I don't have access to Oracle either, so my preffered solution would be (again) to use a PreparedStatement Example code (not very efficient, the DateFormat should be reused instead of recreating it each time. Preferrably by using it from a ThreadLocal since it's not thread-safe): public static void getSqlDate(String date) { java.sql.Date result = null; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); try { result = new java.sql.Date(dateFormat.parse(date).getTime()); } catch (ParseException e) { // Logging goes here } return result; } String strDate = "2009-02-28"; PreparedStatement pstmt = conn.prepareStatement("SELECT d.insertion_date FROM d WHERE CAST(d.insertion_date as date) >= ?"); pstmt.setDate(1, getSqlDate(strDate)); Regards, Stephan.