Re: How to insert "date" as timestamp
От | Roland Walter |
---|---|
Тема | Re: How to insert "date" as timestamp |
Дата | |
Msg-id | 434E2477.2080304@mosaic-ag.com обсуждение исходный текст |
Ответ на | Re: How to insert "date" as timestamp (Aydın Toprak <aydin.toprak@intengo.com>) |
Ответы |
Re: How to insert "date" as timestamp
|
Список | pgsql-jdbc |
Aydın Toprak schrieb: > Hi, > > My Object is java.util.Date ... first of all; > I make an instance of the Date object > > Date date = new Date(); > > then > > I am wirting the set methods of the preparedstatement as > > query.setDate(1,date); > > however eclipse gives an error message, which is "The method > setDate(int, Date) in the type PreparedStatement is not applicable for > the arguments (int, Date)"... > <b>(but eclipse say that it can!)</b> > You need to convert java.util.Date to java.sql.Date if you want only to store the date without the time in a database field DATE. Then you can use setDate(). If you want to store it in a database field TIMESTAMP you must convert the java.util.Date to java.sql.Timestamp. Then you can use query.setTimestamp(1, timestamp); If you use setDate with an java.sql.Date here, you loose the information of the time, even if the Database field is of the type TIMESTAMP. The conversion works as the following, i. e.: java.util.Date date = new java.util.Date(System.currentTimeMillis()); java.sql.Timestamp timestamp = new java.sql.Timestamp(date.getTime()); It is the same for the conversion to java.sql.Date. Regards, Roland. -- Roland Walter phone: +49 (0) 22 25 / 88 2-41 1 MOSAIC SOFTWARE AG fax: +49 (0) 22 25 / 88 2-20 1 Am Pannacker 3 mailto: rwa (at) mosaic-ag (dot) com D-53340 Meckenheim http://www.mosaic-ag.com ------- L E G A L D I S C L A I M E R --------- Die Informationen in dieser Nachricht sind vertraulich und ausschliesslich fuer den Adressaten bestimmt. Kenntnisnahme durch Dritte ist unzulaessig. Die Erstellung von Kopien oder das Weiterleiten an weitere, nicht originaere und benannte Adressaten ist nicht vorgesehen und kann ungesetzlich sein. Die Meinungen in dieser Nachricht stellen lediglich die Meinungen des Senders dar. Falls Sie vermuten, dass diese Nachricht veraendert wurde, setzen Sie sich mit dem Absender in Verbindung. Der Absender uebernimmt ohne weitere Ueberpruefung keine Verantwortung fuer die Richtigkeit und Vollstaendigkeit des Inhalts. Unbefugte Empfaenger werden gebeten, die Vertraulichkeit der Nachricht zu wahren und den Absender sofort ueber einen Uebertragungsfehler zu informieren. ------------------------------------------------------
В списке pgsql-jdbc по дате отправления: