This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 奇怪的JDBC问题开发平台,BEA Weblogic workshop 8.1
对于相同的语句
oracle.sql.CLOB clob = (oralce.sql.CLOB)rs.getClob("content")
其中字段content类型是Clob
问题如下:
如果我从一个连接池中获得一个数据库连接,
那上面语句会抛出一个ClassCastException
但我用下面方法得到数据库连接的话
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection con =DriverManager.getConnection(
"jdbc:oracle:thin:@192.16 8.1.52:1521:SONIC", "scott", "tiger");
那上面取Clob语句正确,对取出数据库中Clob值
这是为什么呢?
-rabbitbug(兔八哥);
2003-10-20
{511}
(#1422374@0)
-
It depends on your rs type. oralce.sql.CLOB implements java.sql.Clob while oracle.jdbc.driver.OracleResultSet implements java.sql.ResultSetso, if your rs type is java.sql.ResultSet, the return type of rs.getClob("content") is Clob not CLOB, cast Exceprion occurs here.
if your rs type is oracle.jdbc.driver.OracleResultSet, the return type of rs.getClob("content") is CLOB, and you don't need cast it at all.
-yuanzidan(原子弹);
2003-10-20
{283}
(#1422408@0)
-
实际情况好象不太一样我用java.sql.ResultSet
getClob()----返回是java.sql.Clob,因此我用(oracle.sql.CLOB)rs.getClob("content")进行转化;
我也用过oracle.sql.OracleResultSet
getClob()---还是返加javq.sql.Clob
getCLOB()---返回oracle.sql.CLOB
用过上过二个方法,都是不行
关键是我用JDBC直接连接数据库时
oracle.sql.CLOB clob = (oralce.sql.CLOB)rs.getClob("content")
这句执行正确
而从连接池取得连接时,这名才报错
-rabbitbug(兔八哥);
2003-10-20
{394}
(#1422442@0)
-
1.2.3.1 you do not have to use oracle type. java.sql.Clob is recommended.
2.if you have to use oracel.sql.CLOB, you have to set your WL's pool wrapper, inside the wrapper, you configure it using oracle JDBC instead of WL JDBC. Or you never get the oracle CLOB type. Do not ask me how to configure it, because I did not use it for long.
3.you need to read the "thinking in Java" about interface and class.
-ra_95(小人--我胡汉三又....);
2003-10-21
{403}
(#1424488@0)
-
查一查你的WEBLOGIC的CLASSPATH中的JDBC和你直接连数据库的JDBC是否是一个版本, 如果用CONNECTION CACHE, 用的是WEBLOGIC的JDBC.
-badegg(badegg);
2003-10-20
(#1423451@0)
-
实际上我用的都是缺省的设置
-rabbitbug(兔八哥);
2003-10-20
{701}
(#1423810@0)
-
I am sure the weblogic using the different Oracle JDBC driver, check the weblogic classpath and bootclasspath, overwrite that JDBC driver using your classes12.jar, it will be fine.
-badegg(badegg);
2003-10-21
(#1424369@0)