Click to See Complete Forum and Search --> : Why throw CastException?


sunnycode
September 16th, 2004, 07:04 PM
Hi,
I have a code that was compiled fine, but run with some error, please help solve.
Thanks in advance!
==================code===============================
import java.sql.*;
import java.io.*;

public class JDBCOpen implements Serializable{
static Connection con; // database connection object
static String dsn = "jdbc:tibcosoftwareinc:oracle://con02:1521;SID=info";
static String user = "scott";
static String password = "tiger";

public Connection getJDBCOpen() throws SQLException {

// Connect to the database
System.out.println("===[2.1.1] within public class Open=====\n");

try{
//Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
Class.forName("tibcosoftwareinc.jdbc.oracle.OracleDriver");
System.out.println("===[2.1.2] within public class Open Class.forName()");
} catch (ClassNotFoundException cnf)
{ }
System.out.println("===[2.1.3] within public class Open Class.forName()");
con =(Connection) DriverManager.getConnection(dsn, user, password);

//to commit
System.out.println("con= " + con );
System.out.println("dsn= " + dsn );
System.out.println("user= " + user );
System.out.println("password= " + password );
System.out.println("===[2.1.6] within public class Open Class.forName()");

//con.setAutoCommit(false);
return con;

}
}

==================Error===========================

===[2.1.1] within public class Open=====


===[2.1.2] within public class Open Class.forName()

===[2.1.3] within public class Open Class.forName()

con= tibcosoftwareinc.jdbc.oracle.OracleConnection@12ebf9a

dsn= jdbc:tibcosoftwareinc:oracle://con02:1521;SID=info

user= scott

password= tiger

===[2.1.6] within public class Open Class.forName()

java.lang.ClassCastException

java.lang.ClassCastException

at com.tibco.plugin.share.java.JavaObjectConverter.convertToString(JavaObjectConverter.java:1020)

at com.tibco.plugin.share.java.JavaObjectConverter.convertToTypedValue(JavaObjectConverter.java:983)

at com.tibco.xml.conversion.helpers.ContentBuilder.getValue(ContentBuilder.java:708)

at com.tibco.xml.factory.XmlInstanceFactory.startElement(XmlInstanceFactory.java:181)

at com.tibco.xml.factory.XmlInstanceFactory.generateElementFromType(XmlInstanceFactory.java:497)

at com.tibco.xml.conversion.helpers.XmlCursor4Java.generateElementFromType(XmlCursor4Java.java:2404)

at com.tibco.xml.conversion.helpers.j.d4(ItemInfo.java:296)

at com.tibco.xml.conversion.helpers.j.d2(ItemInfo.java:121)

at com.tibco.xml.conversion.helpers.XmlCursor4Java.getAttributeStringValue(XmlCursor4Java.java:596)

at com.tibco.xml.data.cursor.XmlCursorSupport.getOverrideTypeStringValue(XmlCursorSupport.java:215)

at com.tibco.xml.conversion.helpers.XmlCursor4Java.hasXsiNamespace(XmlCursor4Java.java:2121)

at com.tibco.xml.conversion.helpers.XmlCursor4Java.moveToFirstNamespace(XmlCursor4Java.java:1264)

at com.tibco.xml.data.cursor.helpers.XmlCursorBase.serialize(XmlCursorBase.java:740)

at com.tibco.xml.conversion.javaschema.Java2Xml.object2XmlContent(Java2Xml.java:547)

at com.tibco.xml.conversion.javaschema.Java2Xml.object2XiNode(Java2Xml.java:283)

at com.tibco.plugin.share.java.JavaObjectConverter.appendObject(JavaObjectConverter.java:569)

at com.tibco.plugin.share.java.JavaObjectConverter.appendObject(JavaObjectConverter.java:423)

at com.tibco.plugin.java.JavaMethodActivity.for(JavaMethodActivity.java:223)

at com.tibco.plugin.java.JavaMethodActivity.eval(JavaMethodActivity.java:118)

at com.tibco.pe.plugin.Activity.eval(Activity.java:207)

at com.tibco.pe.core.TaskImpl.eval(TaskImpl.java:398)

at com.tibco.pe.core.Job.a(Job.java:591)

at com.tibco.pe.core.Job.if(Job.java:443)

at com.tibco.pe.core.JobDispatcher$a.a(JobDispatcher.java:270)

at com.tibco.pe.core.JobDispatcher$a.run(JobDispatcher.java:218)

Demonpants Software
September 17th, 2004, 03:35 AM
The exception it is giving you is a ClassCastException, and from what I can see by the exception output it is caused by the Connection class's lack of any serializability. Although that doesn't make sense because every Object has a toString.

More likely the problem is here:
con = (Connection) DriverManager.getConnection(dsn, user, password);
as it is the only class casting you are performing. Howeverm the getConnection method does in fact return a Connection, so you shouldn't even need to cast anything...

Just by looking at it I can't see any obvious sources. Try commenting out various lines to see what happens. Also, you should have a toString() method if you implemented Serializable.

Try posting it again inside the [ CODE ] tag so that it stays formatted correctly and we can actually read it.

Good luck.

cjard
September 17th, 2004, 07:35 AM
USE [CODE] ... [/CODE] TAGS

the code you have posted does not throw a class cast exception. the fault lies within the the code in file com\tibco\plugin\share\java\JavaObjectConverter.java method convertToString on line 1020

your question cannot be answered here (insufficient information)