首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

奇怪的错误java.lang.ClassCastException: oracle.sql.CLOB

2012-08-25 
奇怪的异常java.lang.ClassCastException: oracle.sql.CLOBoracle.sql.CLOB clob null stmt conn.crea

奇怪的异常java.lang.ClassCastException: oracle.sql.CLOB
oracle.sql.CLOB clob =null; stmt = conn.createStatement(); rs = stmt.executeQuery(sql); if (rs.next()) { System.out.println(rs.getClob(column).getClass()); clob = (oracle.sql.CLOB) rs.getClob(column); out = new BufferedWriter(clob.getCharacterOutputStream()); in = new BufferedReader(new StringReader(data)); }



这个代码很奇怪,看试没有一点问题,但是,项目跑起来后,代码
clob = (oracle.sql.CLOB) rs.getClob(column);
都会抛出java.lang.ClassCastException: oracle.sql.CLOB异常(WEB容器使用的是TOMCAT5.5),先以为是类型转换的问题,
System.out.println(rs.getClob(column).getClass());
但打印出来的是oracle.sql.clob
后又以为是驱动的问题,把classes12.jar换成了ojdbc14.jar
可问题还没有解决

解决的方法:

在网上狂找,终于找到一位高人写的一篇高水平的文章(主要是把我的问题给解决了,哈)

是因为驱动包重复了,我理解为类重名,我使用的是tomcat数据源,哪么,$TOMCAT_HOME$\comm\lib目录下需要oracle驱动包,是给tomcat创建jndi数据源时用的,而项目中也要有oracle驱动包,是给程序编译用的,最后使用eclilpse的java build path进行外部引用,使用应用程序编译通过,但也不会把ojdbc14.jar的驱动包引入到发布目录,再试,果然解决了问题。

?

转自:http://spring3000.iteye.com/blog/372482

热点排行
Bad Request.