Skip to content
Snippets Groups Projects
Commit 4d84b7a1 authored by Bruce Momjian's avatar Bruce Momjian
Browse files

I just got bitten by this too. I use type timestamp in the

database, and often need the latest timestamp, but want to
format it as a date. With 7.0.x, I just

 select ts from foo order by ts desc limit 1

and in java: d = res.getDate(1);

but this fails everywhere in my code now :(

http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame7.html

says

  The ResultSet.getXXX methods will attempt to
  convert whatever SQL type was returned by the
  database to whatever Java type is returned by
  the getXXX method.

Palle Girgensohn
parent 5b42666f
No related branches found
No related tags found
No related merge requests found
......@@ -423,8 +423,13 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
String s = getString(columnIndex);
if(s==null)
return null;
return java.sql.Date.valueOf(s);
// length == 10: SQL Date
// length > 10: SQL Timestamp, assumes PGDATESTYLE=ISO
try {
return java.sql.Date.valueOf((s.length() == 10) ? s : s.substring(0,10));
} catch (NumberFormatException e) {
throw new PSQLException("postgresql.res.baddate", s);
}
}
/**
......@@ -441,8 +446,13 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
if(s==null)
return null; // SQL NULL
return java.sql.Time.valueOf(s);
// length == 8: SQL Time
// length > 8: SQL Timestamp
try {
return java.sql.Time.valueOf((s.length() == 8) ? s : s.substring(11,19));
} catch (NumberFormatException e) {
throw new PSQLException("postgresql.res.badtime",s);
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment