Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U5ews-0000a1-QD for pgsql-jdbc@arkaria.postgresql.org; Wed, 13 Feb 2013 16:12:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1U5ewr-0007AO-Lo for pgsql-jdbc@arkaria.postgresql.org; Wed, 13 Feb 2013 16:12:41 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U5ewj-00073E-8B for pgsql-jdbc@postgresql.org; Wed, 13 Feb 2013 16:12:33 +0000 Received: from plane.gmane.org ([80.91.229.3]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1U5ewh-0008Um-4F for pgsql-jdbc@postgresql.org; Wed, 13 Feb 2013 16:12:32 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1U5eww-0001TJ-8l for pgsql-jdbc@postgresql.org; Wed, 13 Feb 2013 17:12:46 +0100 Received: from 217.110.94.121 ([217.110.94.121]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 13 Feb 2013 17:12:46 +0100 Received: from spam_eater by 217.110.94.121 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 13 Feb 2013 17:12:46 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Thomas Kellerer Subject: Re: Timestamp vs. Java Date/Timestamp Date: Wed, 13 Feb 2013 17:13:06 +0100 Lines: 34 Message-ID: References: <1360043227.14635.9.camel@localhost> <1360733845.24220.50.camel@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 217.110.94.121 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 In-Reply-To: <1360733845.24220.50.camel@localhost> X-Pg-Spam-Score: 1.8 (+) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Andreas Reichel, 13.02.2013 06:37: > On the same time java.sql.Date and java.util.Date support time > information and in fact you can handover a java.sql.Date parameter to a > Timestamp field. But due to the removing of the time part this will *not* work. > This is the part when I get confused: the timestamp field holds time > information, the java.sql.Date parameter holds time information -- still > it is cut off in the middle. Yes, that's per documentation. http://docs.oracle.com/javase/6/docs/api/java/sql/Date.html "To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero [...]" Note the part about "setting ... to zero" So as soon as you create a java.sql.Date you lose the time information. If you want to be JDBC compliant there are only two simple things to remember: * use java.sql.Date together with setDate()/getDate() for date columns * use java.sql.Timestamp together with setTimestamp()/getTimestamp() for timestamp columns This works across all DBMS that I have worked with (Oracle is a bit special but in general you should simply treat their DATE as timestamp) The only problem are columns with timezones as none of the Java classes can deal with that. Thomas -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc