Skip site navigation (1) Skip section navigation (2)

datetime conversion to JDBC

From: "Wendy L(dot) Fry" <fry(at)cmf(dot)nrl(dot)navy(dot)mil>
To: pgsql-sql(at)postgresql(dot)org
Cc: fry(at)cmf(dot)nrl(dot)navy(dot)mil
Subject: datetime conversion to JDBC
Date: 2000-03-06 20:23:53
Message-ID: 200003062025.PAA22714@ginger.cmf.nrl.navy.mil (view raw or flat)
Thread:
Lists: pgsql-sql
I have a PostgreSQL database that is acting sort of like a datebook.  One
of the tables in the database has a column for storing a begin date and a
column for an end date.  I've made the data type of these two columns
timestamp (I've tried datetime as well).

I'm writing Java code to perform queries on the database, for example:

Statement stmt = con.createStatement();
              
String command = "SELECT * FROM dates WHERE ((dates.fromDate >= '2000-2-1
00:00:00') AND (dates.toDate <= '2000-3-1 00:00:00'))";
ResultSet rs = stmt.executeQuery(command);

String name = rs.getString(1);
int activityID = rs.getInt(2);
Timestamp beginDate = rs.getTimestamp(3);
Timestamp endDate = rs.getTimestamp(4);

Getting the name and activityID work fine, but the next lines cause an
"SQLException: Bad abstime external representation ''"

I've tried to use types Date, String, and Object instead of Timestamp in
the java code and they all return the same error.

What is the correct way to get the column value in Java when the PostgreSQL
column type is timestamp?

I initially was representing dates in my database as integers (one integer
column for each: month, day, year, hour, minute, second) but that made
queries on the date extremely difficult to do.  Using a type such as
timestamp and datetime simplify the query greatly and I'd like to be able
to use them.

Thank you for any help anyone can offer.  I've been unable to find any
references to this problem in any of the mailing archives or PostgreSQL
documentation.

Sincerely,

Wendy Fry

pgsql-sql by date

Next:From: Zot O'ConnorDate: 2000-03-07 04:47:21
Subject: change owner of database -- answer
Previous:From: Ray MessierDate: 2000-03-06 18:11:10
Subject: re: [SQL] Best method

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group