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
Branches
Tags
No related merge requests found
...@@ -423,8 +423,13 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -423,8 +423,13 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
String s = getString(columnIndex); String s = getString(columnIndex);
if(s==null) if(s==null)
return null; return null;
// length == 10: SQL Date
return java.sql.Date.valueOf(s); // 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 ...@@ -441,8 +446,13 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
if(s==null) if(s==null)
return null; // SQL NULL return null; // SQL NULL
// length == 8: SQL Time
return java.sql.Time.valueOf(s); // 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.
Please register or to comment