You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by "Robert S. Sfeir" <ro...@codepuccino.com> on 2004/02/03 14:57:12 UTC
[PATCH] PlatformDefaultImpl in RC5 throwing ClassCastException
:-\
I guess no comments from the Oracle coders out there... Can we then
include this fix somehow so I don't have to keep 'fixing' my nightly
builds, and certainly not 1.0? This bug only affect Oracle impls.
Tested it with Postgres and MySQL, ran JUnit tests and they all pass.
Tested it with my app on various DBs, and things work as expected, no
more ClassCastException.
again the change is from:
PlatformDefaultImpl line 255
public void setObjectForStatement(PreparedStatement ps, int index,
Object value, int sqlType)
throws SQLException
{
if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
{
String s = (String) value;
ps.setCharacterStream(index, new StringReader(s), s.length());
}
else
{
ps.setObject(index, value, sqlType);
}
}
to:
public void setObjectForStatement(PreparedStatement ps, int index,
Object value, int sqlType)
throws SQLException
{
if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
{
String s = (String) value;
ps.setCharacterStream(index, new StringReader(s), s.length());
}
else if ((value instanceof String)) // setString() if value is
String, not Object
{
ps.setString( index, value.toString());
}
else
{
ps.setObject(index, value, sqlType);
}
}
Thanks
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org
Re: [PATCH] PlatformDefaultImpl in RC5 throwing ClassCastException
Posted by Andy Malakov <an...@transdecisions.com>.
Hello Robert,
I am using Oracle 9.2.0 with RC5 and CVS Head. I do not see the same problem.
I have a question about your original e-mail:
ps.setObject(index, value, sqlType); <--- Poops out right here
What is the value of sqlType in your case?
Here is decompiled oracle.jdbc.driver.OraclePreparedStatement.setObject from ojdbc14_g.jar (may be it will help?):
public synchronized void setObject(int paramIndex, Object x, int targetSqlType, int scale) throws SQLException {
if(OracleLog.TRACE)
OracleLog.print(this, 1, 16, 1, "OraclePreparedStatement.setObject(paramIndex=" + paramIndex + ", object,
targetSqlType=" + targetSqlType + ", scale=" + scale + ")");
if(x == null && targetSqlType != 2002 && targetSqlType != 2008 && targetSqlType != 2003 && targetSqlType != 2007 &&
targetSqlType != 2006)
setNull(paramIndex, targetSqlType);
else
switch(targetSqlType) {
case 1: // '\001'
if(x instanceof CHAR)
setCHAR(paramIndex, (CHAR)x);
else
setString(paramIndex, (String)x);
break;
case 12: // '\f'
setString(paramIndex, (String)x);
break;
case 999:
setFixedCHAR(paramIndex, (String)x);
break;
case -1:
setString(paramIndex, (String)x);
break;
case 2: // '\002'
if(x instanceof NUMBER) {
setNUMBER(paramIndex, (NUMBER)x);
break;
}
if(x instanceof Byte) {
setByte(paramIndex, ((Byte)x).byteValue());
break;
}
if(x instanceof Short) {
setShort(paramIndex, ((Short)x).shortValue());
break;
}
if(x instanceof Integer) {
setInt(paramIndex, ((Integer)x).intValue());
break;
}
if(x instanceof Long) {
setLong(paramIndex, ((Long)x).longValue());
break;
}
if(x instanceof Float) {
setFloat(paramIndex, ((Float)x).floatValue());
break;
}
if(x instanceof Double)
setDouble(paramIndex, ((Double)x).doubleValue());
else
setBigDecimal(paramIndex, (BigDecimal)x);
break;
case 3: // '\003'
setBigDecimal(paramIndex, (BigDecimal)x);
break;
case -7:
setBoolean(paramIndex, ((Boolean)x).booleanValue());
break;
case -6:
setByte(paramIndex, ((Number)x).byteValue());
break;
case 5: // '\005'
setShort(paramIndex, ((Number)x).shortValue());
break;
case 4: // '\004'
setInt(paramIndex, ((Number)x).intValue());
break;
case -5:
setLong(paramIndex, ((Number)x).longValue());
break;
case 6: // '\006'
case 7: // '\007'
setFloat(paramIndex, ((Number)x).floatValue());
break;
case 8: // '\b'
setDouble(paramIndex, ((Number)x).doubleValue());
break;
case -2:
if(x instanceof RAW)
setRAW(paramIndex, (RAW)x);
else
setBytes(paramIndex, (byte[])x);
break;
case -3:
setBytes(paramIndex, (byte[])x);
break;
case -4:
setBytes(paramIndex, (byte[])x);
break;
case 91: // '['
if(x instanceof DATE)
setDATE(paramIndex, (DATE)x);
else
setDate(paramIndex, (Date)x);
break;
case 92: // '\\'
setTime(paramIndex, (Time)x);
break;
case 93: // ']'
if(x instanceof TIMESTAMP)
setTIMESTAMP(paramIndex, (TIMESTAMP)x);
else
setTimestamp(paramIndex, (Timestamp)x);
break;
case -100:
setTIMESTAMP(paramIndex, (TIMESTAMP)x);
break;
case -101:
setTIMESTAMPTZ(paramIndex, (TIMESTAMPTZ)x);
break;
case -102:
setTIMESTAMPLTZ(paramIndex, (TIMESTAMPLTZ)x);
break;
case -103:
setINTERVALYM(paramIndex, (INTERVALYM)x);
break;
case -8:
setROWID(paramIndex, (ROWID)x);
break;
case 2004:
setBLOB(paramIndex, (BLOB)x);
break;
case 2005:
setCLOB(paramIndex, (CLOB)x);
break;
case -13:
setBFILE(paramIndex, (BFILE)x);
break;
case 2002:
case 2008:
setSTRUCT(paramIndex, STRUCT.toSTRUCT(x, connection));
break;
case 2003:
setARRAY(paramIndex, (ARRAY)x);
break;
case 2007:
setOPAQUE(paramIndex, (OPAQUE)x);
break;
case 2006:
setREF(paramIndex, (REF)x);
break;
default:
DBError.throwSqlException(4);
break;
}
}
----- Original Message -----
From: "Robert S. Sfeir" <ro...@codepuccino.com>
To: "OJB Developers List" <oj...@db.apache.org>
Sent: Tuesday, February 03, 2004 8:57 AM
Subject: [PATCH] PlatformDefaultImpl in RC5 throwing ClassCastException
> :-\
>
> I guess no comments from the Oracle coders out there... Can we then
> include this fix somehow so I don't have to keep 'fixing' my nightly
> builds, and certainly not 1.0? This bug only affect Oracle impls.
> Tested it with Postgres and MySQL, ran JUnit tests and they all pass.
> Tested it with my app on various DBs, and things work as expected, no
> more ClassCastException.
>
> again the change is from:
> PlatformDefaultImpl line 255
>
> public void setObjectForStatement(PreparedStatement ps, int index,
> Object value, int sqlType)
> throws SQLException
> {
> if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
> {
> String s = (String) value;
> ps.setCharacterStream(index, new StringReader(s), s.length());
> }
> else
> {
> ps.setObject(index, value, sqlType);
> }
> }
>
> to:
>
> public void setObjectForStatement(PreparedStatement ps, int index,
> Object value, int sqlType)
> throws SQLException
> {
> if ((value instanceof String) && (sqlType == Types.LONGVARCHAR))
> {
> String s = (String) value;
> ps.setCharacterStream(index, new StringReader(s), s.length());
> }
> else if ((value instanceof String)) // setString() if value is
> String, not Object
> {
> ps.setString( index, value.toString());
> }
> else
> {
> ps.setObject(index, value, sqlType);
> }
> }
>
>
> Thanks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org