Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMJjW-0002u8-Fr for pgsql-jdbc@arkaria.postgresql.org; Tue, 05 Dec 2017 20:22:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMJjV-0003R6-CA for pgsql-jdbc@arkaria.postgresql.org; Tue, 05 Dec 2017 20:22:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eMJjV-0003Qv-4x for pgsql-jdbc@lists.postgresql.org; Tue, 05 Dec 2017 20:22:25 +0000 Received: from mail-qt0-x231.google.com ([2607:f8b0:400d:c0d::231]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eMJjR-0001R8-R4 for pgsql-jdbc@postgresql.org; Tue, 05 Dec 2017 20:22:24 +0000 Received: by mail-qt0-x231.google.com with SMTP id d4so3868294qtj.5 for ; Tue, 05 Dec 2017 12:22:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:date:in-reply-to:references:mime-version :content-transfer-encoding; bh=qKr6s2r6bJobRKMZVSimRt+QQ4imOlGJ8rw9YtsbWIE=; b=ue2tOp8EEp7xbgRAlFAIG0behwApMhmpx6DCqNO7CmNfFa+MBiMdoWSkAEfedp4Upx IA/35I1/nYhV6VIcNEhLJb4+kNoKUOLA+ML0Jo5aRUeBZTmqrPaRz+erNE9T25ynvqol eATgp0TZklDJxk9F1LELGmTI55OK2G0UPJpedSvbcj8nGBx57+dMWdJix0r6m3WOHLle x5yPxaczGI+Utq+Mmo7MvEE+O0/woe2x1a8mosVnfm4ZcjajKjGCjUUiLA5lY/g5yNEH deetV4J1Okv2lUEIWd0ajGt+O0YPEZJ+gU7JNdYce7iChDe8G+DiAgzNENQpy89Ca/Pq 6E0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=qKr6s2r6bJobRKMZVSimRt+QQ4imOlGJ8rw9YtsbWIE=; b=l0C18ZihPztwYuOMrwpBeEWO6RLvOM9cFl5EPWg9M/4cG1UVtgZTF0sCfdy9Ws8P+i rdJP3V3mw/bTXVBFOh2ddbm8tBZp2CXVt5ffuc7y0RhQlpv6slDCJGQ+j47rSZwX6ioj 9zTgz76HNeMrykwZNWhClH8YMxRzOFoWHfgEq3UsNxIR/LmSTENW8MaubrSgPECdvxYp 7joN4wv7tNt4bYg+m2fYBtPA8Y/+vdVAss9QDUFUfvYOf1Ei9F1WQ0ompahbfE/lZwAL lJdw/ZA56Pp87Ncv5rEIQZuUh6sT2MOXSIab87Ch/FpyiYGsiyD4AVelL1kQdDrzuQQU u+bA== X-Gm-Message-State: AKGB3mJLqSm/W/22YK2FtgCJPmz721L3fyy36kO7YqlTvMLgIu1lCxAJ yl5DgBLdV+NMKiYzfloJ57M= X-Google-Smtp-Source: AGs4zMZLWlN1vjAOWTZuJRAIhSZkTU4c1X7jBGIY3j4ETCQoBgNjWKc9/tp95CFBJlbDIK5jQ5/a1g== X-Received: by 10.200.38.133 with SMTP id 5mr3082681qto.317.1512505339616; Tue, 05 Dec 2017 12:22:19 -0800 (PST) Received: from roblaptop ([2804:14d:baa0:8491:461e:a1ff:fe19:c7bd]) by smtp.gmail.com with ESMTPSA id v17sm554661qkl.36.2017.12.05.12.22.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Dec 2017 12:22:18 -0800 (PST) Message-ID: <1512505335.4814.5.camel@gmail.com> Subject: Re: "could not determine data type of parameter" with timestamp From: rob stone To: =?ISO-8859-1?Q?R=E9mi?= Aubel , pgsql-jdbc@postgresql.org Date: Wed, 06 Dec 2017 07:22:15 +1100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.2-1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, 2017-12-05 at 15:11 +0000, Rémi Aubel wrote: > Hello, > > > > The solution given 4 years ago was to explicitly cast the parameter > as a timestamp (select * from my_table where ?::timestamp is null). > But this workaround is not really useful for me, because my > application uses generated (dynamic) queries and targets multiple > database types (not only PosgreSQL). So, when I know the targeted > database, I do not know my parameter types anymore. > > Any suggestion? > > Thanks in advance. > > Rémi. > > Hi Rémi, After creating the Prepared Statement you can do a ResultSetMetaData.getMetaData() which returns an object containing the data types of the columns in your select list. Then for each column in your "where" clause you can obtain its data type and then do setLong, setString, setTimeStamp or whatever, according to its type. Then do the "execute" to obtain the actual result set. HTH, Rob