Subject org.firebirdsql.jdbc.field.TypeConvertionException: Error converting to long.
Author joerg_froeber
Hello,

in use is Firebird v2.0.3 and jaybird 2.1.1.

A Resultset is used to populate a PreparedStatement using the
following code (rs = ResultSet, sql = SQL-String, rsmd =
ResultSetMetaData):

while (rs.next())
{
PreparedStatement ps = con.prepareStatement(sql);
for (int i = 1; i <= rsmd.getColumnCount(); i++)
{
switch (rsmd.getColumnType(i))
{
case Types.INTEGER: case Types.SMALLINT: case Types.TINYINT:
{
ps.setInt(i, rs.getInt(i));
break;
}
case Types.BIGINT:
{
ps.setLong(i, rs.getLong(i));
break;
}
case Types.DECIMAL: case Types.NUMERIC:
{
ps.setBigDecimal(i, rs.getBigDecimal(i));
break;
}
case Types.DOUBLE: case Types.FLOAT: case Types.REAL:
{
ps.setDouble(i, rs.getDouble(i));
break;
}
case Types.DATE:
{
ps.setDate(i, rs.getDate(i));
break;
}
case Types.TIME:
{
ps.setTime(i, rs.getTime(i));
break;
}
default:
{
String temp = rs.getString(i);
if (temp == null)
temp = "";
ps.setString(i, temp);
}
}
}
ps.execute();
ps.close();
}

the problematic field is of the domain num15_0, which is defined as:
CREATE DOMAIN NUM15_0 AS
NUMERIC(15,0)
DEFAULT 0
NOT NULL;

When debugging, the rsmd.getColumnType(i) of the num15_0 field
resolves to 12, which is the constant for java.sql.Types.VARCHAR. So
the default case of the switch-statement is called and the following
error occurs:
org.firebirdsql.jdbc.field.TypeConvertionException: Error converting
to long.
at
org.firebirdsql.jdbc.field.FBLongField.setString(FBLongField.java:131)
at
org.firebirdsql.jdbc.AbstractPreparedStatement.setString(AbstractPreparedStatement.java:384)
at
de.indv.db.DBConnection.executePreparedStatement(DBConnection.java:129)

Is there a bug in firebird/jaybird or am I doing something wrong?

Kind regard
Jörg Fröber