pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Esteban Chiner Sanz <echiner@tissat.es>
To: Jon Windfeld Bundesen <jon@it-konsulenterne.dk>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] What JDBC datatype can be used for DATETIME ?
Date: Fri, 20 Aug 1999 08:47:03 +0200
Message-ID: <37BCF9E6.403A5EA8@tissat.es> (raw)
References: <37BC25CD.DB267B3F@it-konsulenterne.dk>

I had the same problem and I finally ended up using the timestamp type in postgres
and using the getTimestamp function y Java. That worked fine for me.

                Esteban Chiner

Jon Windfeld Bundesen escribió:

>  I'm trying to read a DATETIME field from my Pg 6.4.2 using JDBC.
>
> When i try reading the date from my ResultSet using ResultSet.getDate()
> i get an error stating:
>
> java.sql.SQLException: Bad Date Format: at 0 in Thu Aug 19 12:19:52 1999
>
> CEST
>  at postgresql.ResultSet.getDate(ResultSet.java:407)
>  at TestDate.main(TestDate.java:32)
>
> When i try using ResultSet.getTimestamp() instead, i also get an error:
> java.lang.NumberFormatException:  1999 CEST
>  at java.lang.Float.<init>(Float.java)
>  at postgresql.ResultSet.getTimestamp(ResultSet.java:455)
>  at TestDate.main(TestDate.java:32)
>
> I CAN use getString(), but i'd like to get a real Date object, not just
> a String. Can anyone help ?
>
> Best regards,
>     Jon Bundesen.
>
> Here is the code if anyone is interested:
> ===========================
>
> Table = foo
> +----------------------------------+----------------------------------+-------+
>
> |              Field                                |
> Type                               | Length|
> +----------------------------------+----------------------------------+-------+
>
> | dt                                                 |
> datetime                                       |     8     |
> +----------------------------------+----------------------------------+-------+
>
> import java.sql.*;
> import java.sql.Date;
>
> public class TestDate {
>
>   public static void main (String args[])
>     throws Exception
>   {
>     Connection con;
>     Statement statement;
>     PreparedStatement preparedStatement;
>     ResultSet rs;
>     // String url = "jdbc:postgresql:test1";
>     String url = "jdbc:postgresql://127.0.0.1:5432/test1";
>
>     Class.forName("postgresql.Driver");
>     con = DriverManager.getConnection(url, "jon", "");
>     con.setAutoCommit( false );
>
>     //
>
>     statement = con.createStatement();
>     statement.executeUpdate("insert into foo values ( current_timestamp
> )");
>     con.commit();
>     statement.close();
>
>     //
>
>     statement = con.createStatement();
>     rs = statement.executeQuery("SELECT * FROM foo");
>     while (rs.next()) {
>       System.out.println("Result: " + rs.getTimestamp(1));
>       //System.out.println("Result: " + rs.getDate(1));
>     }
>     rs.close();
>     statement.close();
>
>     //
>
>     con.close();
>   }
> }
>
> ************

------------------------------------------------------------
 Esteban Chiner Sanz        mailto (work): echiner@tissat.es
 TISSAT
 Av. Aragon, 30, 5ª planta  Phone: 96 393 9950
 Valencia (SPAIN)





view thread (4+ messages)  latest in thread

Message-ID: <37BCF9E6.403A5EA8@tissat.es>
Permalink:  ../37BCF9E6.403A5EA8@tissat.es/
Also on:    postgresql.org/message-id/37BCF9E6.403A5EA8@tissat.es

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: echiner@tissat.es, jon@it-konsulenterne.dk
  Subject: Re: [SQL] What JDBC datatype can be used for DATETIME ?
  In-Reply-To: <37BCF9E6.403A5EA8@tissat.es>
  References: <37BC25CD.DB267B3F@it-konsulenterne.dk> <37BCF9E6.403A5EA8@tissat.es>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox