ClassCastException after upgrading Oracle backend
843854Feb 26 2004 — edited Mar 1 2004Hello!
I used to cast an object to BigDecimal earlier when my Database was Oracle 8i.
now i have upgraded backend to Oracle 9i (9.2.0.4) and i get ClassCastException ast the same line where i cast object to big decimal. Following is the code:
public Vector fetchResults(DBProcedureStatement proc) throws Exception
{
ResultSet results = null;
Vector outParams = new Vector(5, 5);
Vector rows = new Vector(5, 5);
int index = 0;
// ORACLE does not return ResultSets from a stored procedure
// instead it returns an OUT parameter of type OracleTypes.CURSOR
// that contains a ResultSet. When processing a call to an Oracle
// stored procedured the call to CallableStatement.getResultSet will
// always return a null object.
//
// This is only set up to handle a stored procedure that returns
// a single ResultSet if MS SQL Server or someother database
// is used that can return multiple ResultSets from the same
// stored procedure, code needs to be added here to loop through
// all the ResultSets.
try
{
// There may not be a ResultSet for the Stored Procedure
// an Exception will be thrown if there isn't one, so catch it.
results = ((CallableStatement) m_Statement).getResultSet();
}
catch (Exception e) {}
if (results != null)
{
Vector resultRows = null;
// There is a ResultSet so process it
if (proc.checkColumnDataTypes())
{
resultRows = fetchRows(results, true);
}
else
{
resultRows = fetchRows(results);
}
closeResultSet(results);
// Add the Vector containing the rows just fetched from the ResultSet,
// to the Vector that will be returned to the calling program.
rows.addElement(resultRows);
results = null;
resultRows = null;
}
// ONLY AFTER PROCESSING ALL ResultSets should the output parameters
// be processed.
// Start processing the output parameters from the stored procedure
for (index = 0; index < proc.getNumberOfParameters(); index++)
{
DBParameter dbParam = proc.getParameterAt(index);
if (!dbParam.getInput())
{
// found an output parameter, get it from the
// Callable Statement and put it in the Vector to be returned
/*
* I AM TRYING TO CONVERT THIS obj TO BigDecimal
*/
Object obj =
((CallableStatement) m_Statement).getObject(dbParam.getPosition());
switch (dbParam.getSqlType())
{
case oracle.jdbc.driver.OracleTypes.CURSOR:
// Process the Oracle CURSOR as a normal ResultSet
Vector cursorRows = null;
if (proc.checkColumnDataTypes())
{
cursorRows = fetchRows((OracleResultSet) obj, true);
}
else
{
cursorRows = fetchRows((OracleResultSet) obj);
}
rows.addElement(cursorRows);
break;
default:
rows.addElement(obj);
break;
}
dbParam = null;
obj = null;
}
} // end processing output parameters
results = null;
/*
* RETURNING THE Vector OF obj VALUES
*/
return rows;
}
The above returned Vector i am taking in Vector vRs in the calling method and the code snippet is as follows:
int iRet;
if (vRs != null)
{
/*
* FOLLOWING IS THE LINE WHERE I GET ClassCastException.
* /
iRet = ((BigDecimal)vRs.elementAt(1)).intValue();
}
What i was thinking of is to re-write the part of the code for casting.
But is there any way to address this issue? because I have many such castings in my code and i would need to change them all.
Looking forward for some one to help me out.
Thanking in anticipation.
Vikram.