X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id C91709DC8E1 for ; Tue, 10 Jan 2006 16:17:16 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 86416-02 for ; Tue, 10 Jan 2006 16:17:17 -0400 (AST) X-Greylist: whitelisted by SQLgrey- Received: from rly-ip08.mx.aol.com (rly-ip08.mx.aol.com [64.12.138.12]) by postgresql.org (Postfix) with ESMTP id 5E6B89DC8AA for ; Tue, 10 Jan 2006 16:17:14 -0400 (AST) Received: from smtp-los04.proxy.aol.com (smtp-los04.proxy.aol.com [195.93.24.101]) by rly-ip08.mx.aol.com (8.12.11/8.12.11) with ESMTP id k0AKHCtF026772 for ; Tue, 10 Jan 2006 15:17:12 -0500 Received: from [192.168.2.7] (ACD73F2D.ipt.aol.com [172.215.63.45]) by smtp-los04.proxy.aol.com (8.12.11/8.12.11) with ESMTP id k0AKH5Q1030135 for ; Tue, 10 Jan 2006 15:17:05 -0500 Message-ID: <43C41640.8010000@acm.org> Date: Tue, 10 Jan 2006 20:17:04 +0000 From: Jeffrey Leegon User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: JDBC, PrepareStatement and TimeStamp problem Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.43 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.001 required=5 tests=[FORGED_AOL_RCVD=0.001] X-Spam-Score: 0.001 X-Spam-Level: X-Archive-Number: 200601/46 X-Sequence-Number: 14497 I get an error with the timestamps when running the following code: (Varibbles currentTrainStart and stop are GregorianCalendars) String tableName = "\"AdultData\""; String tempSql = "SELECT \"Age\",\"Gender\",\"PrimaryLanguage\",\"TimeOfDay\",\"DayOfWeek\",\"ChiefComplaint\",\"BodyFluidIso\",\"RespIso\",\"Acuity\",\"Consult\",\"Labs\",\"Radiology\","; tempSql+= "\"EKG\",\"MOA\",\"Admitted\" FROM ? "; tempSql +="WHERE \"DATE_ADMITTED\">= ? AND \"DATE_ADMITTED\"< ? ;"; query = conn.prepareStatement(tempSql); query.setString(1, tableName); Timestamp startTrain = new Timestamp(currentTrainStart.getTimeInMillis()); query.setTimestamp(2,startTrain); Timestamp stopTrain = new Timestamp(stop.getTimeInMillis()); query.setTimestamp(3, stopTrain); System.out.println(query.toString()); query.executeQuery(); // query.clearParameters(); When I execute the following code I get the error: java.sql.SQLException: ERROR: syntax error at or near "$1" at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1482) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1267) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:186) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:392) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:330) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:240) at TemporalDataSetCreator.getNextDataSet(TemporalDataSetCreator.java:180) at SequentialBNTest.main(SequentialBNTest.java:31) After initiating the places holders in the prepared statement and call toString() I get the following line going to the DB: SELECT "Age","Gender","PrimaryLanguage","TimeOfDay","DayOfWeek","ChiefComplaint","BodyFluidIso","RespIso","Acuity","Consult","Labs","Radiology","EKG","MOA","Admitted" FROM "AdultData" WHERE "DATE_ADMITTED">= 2004-05-10 00:00:00.000000+0100 AND "DATE_ADMITTED"< 2004-05-31 00:00:00.000000+0100 Which if I put in pgAdmin III and add single quotes around the Timestamps if runs fine. If I add \' around the ? in the prepared statement it gives the ? to the DB and throws and error. What am I doing wrong? Thanks, Jeff