Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4d84b7a

Browse files
committed
I just got bitten by this too. I use type timestamp in the
database, and often need the latest timestamp, but want toformat it as a date. With 7.0.x, I just select ts from foo order by ts desc limit 1and 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.htmlsays 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
1 parent5b42666 commit4d84b7a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

‎src/interfaces/jdbc/org/postgresql/jdbc2/ResultSet.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,13 @@ public java.sql.Date getDate(int columnIndex) throws SQLException
423423
Strings =getString(columnIndex);
424424
if(s==null)
425425
returnnull;
426-
427-
returnjava.sql.Date.valueOf(s);
426+
// length == 10: SQL Date
427+
// length > 10: SQL Timestamp, assumes PGDATESTYLE=ISO
428+
try {
429+
returnjava.sql.Date.valueOf((s.length() ==10) ?s :s.substring(0,10));
430+
}catch (NumberFormatExceptione) {
431+
thrownewPSQLException("postgresql.res.baddate",s);
432+
}
428433
}
429434

430435
/**
@@ -441,8 +446,13 @@ public Time getTime(int columnIndex) throws SQLException
441446

442447
if(s==null)
443448
returnnull;// SQL NULL
444-
445-
returnjava.sql.Time.valueOf(s);
449+
// length == 8: SQL Time
450+
// length > 8: SQL Timestamp
451+
try {
452+
returnjava.sql.Time.valueOf((s.length() ==8) ?s :s.substring(11,19));
453+
}catch (NumberFormatExceptione) {
454+
thrownewPSQLException("postgresql.res.badtime",s);
455+
}
446456
}
447457

448458
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp