Subject Bug in org.firebirdsql.jdbc.FBPreparedStatement ?
Author Agustin Gonzalez
David,
There are a series of statements in FBPrepared statement dealing with dates
that may have a bug. They start at line 807 (see code excerpt below). The
problem is that it seems that once the code enters one of the relevant case
statements (shown below) the code invariably will throw an exception. The
bug seems a cut and paste typo and it seems that an "else is missing". The
way to fix it is to add the missing "else" clauses as shown below:

if (x instanceof java.sql.Date) {
setDate(parameterIndex, (java.sql.Date) x);
} else if (x instanceof java.sql.Timestamp) {
setDate(parameterIndex, new
java.sql.Date(((java.sql.Timestamp) x).getTime()));
} else if (x instanceof String) { // *****NOTE "else" added
here!
setDate(parameterIndex, java.sql.Date.valueOf((String) x));
} else {
throw new SQLException("Invalid conversion to date");
}

In my case, this bug prevented me from using Date types (I am using Castor
as the persistence layer in my project and I am planning to use JBoss too).
I could continue after I fixed the code as suggested.

Thanks,
---
Agustin Gonzalez, Principal
Town Lake Software
www.townlakesoftware.com
(512) 248-9839

P.S. Relevant code:
case GDS.SQL_TYPE_DATE:
if (x instanceof java.sql.Date) {
setDate(parameterIndex, (java.sql.Date) x);
} else if (x instanceof java.sql.Timestamp) {
setDate(parameterIndex, new
java.sql.Date(((java.sql.Timestamp) x).getTime()));
} if (x instanceof String) {
setDate(parameterIndex, java.sql.Date.valueOf((String) x));
} else {
throw new SQLException("Invalid conversion to date");
}
break;
case GDS.SQL_TYPE_TIME:
if (x instanceof java.sql.Time) {
setTime(parameterIndex, (java.sql.Time) x);
} else if (x instanceof java.sql.Timestamp) {
setTime(parameterIndex, new
java.sql.Time(((java.sql.Timestamp) x).getTime()));
} if (x instanceof String) {
setTime(parameterIndex, java.sql.Time.valueOf((String) x));
} else {
throw new SQLException("Invalid conversion to time");
}
break;
case GDS.SQL_TIMESTAMP:
if (x instanceof java.sql.Timestamp) {
setTimestamp(parameterIndex, (java.sql.Timestamp) x);
} else if (x instanceof java.sql.Date) {
setTimestamp(parameterIndex, new
java.sql.Timestamp(((java.sql.Date) x).getTime()));
} if (x instanceof String) {
setTimestamp(parameterIndex,
java.sql.Timestamp.valueOf((String) x));
} else {
throw new SQLException("Invalid conversion to timestamp");
}
break;