gpt4 book ai didi

java - oracle.sql.CLOB 无法转换为 oracle.sql.DatumWithConnection

转载 作者:太空宇宙 更新时间:2023-11-04 10:32:47 27 4
gpt4 key购买 nike

这是我的java代码。我使用的是 Wildfly 10.0.0 和 java 1.8 以及 oracle 12c。

   public void getCellValue(){         
PreparedStatement pstat = getConnection().prepareStatement("select empty_clob() from dual");
resultSet = pstat.executeQuery();
resultSet.next();
DatumWithConnection datum = (DatumWithConnection) resultSet.getClob(1);
OracleConnection oconn = datum.getOracleConnection();
}

public Connection getConnection()
{
InitialContext ic = new InitialContext();
this.mDataSource = ((DataSource)ic.lookup(lookupName));
this.mConnection = this.mDataSource.getConnection();
return this.mConnection;
}

当我调用函数 getCellValue 时,出现这样的错误。

22:18:56,622 ERROR [stderr] (default task-13) java.lang.ClassCastException: oracle.sql.CLOB cannot be cast to

oracle.sql.DatumWithConnection

如何修复此错误?感谢您的观看。

最佳答案

以下代码有效

public class MyTest
{
public static void main(String[] args) throws SQLException {
MyTest test1 = new MyTest();
oracle.jdbc.internal.OracleConnection conn = test1.getConnection();
test1. getCellvalue(conn);
}

private void getCellvalue(Connection dbConnection) throws SQLException {
PreparedStatement pstat = dbConnection.prepareStatement("select empty_clob() from dual");
ResultSet resultSet = pstat.executeQuery();
resultSet.next();
DatumWithConnection datum = (DatumWithConnection) resultSet.getClob(1);
OracleConnection oconn = datum.getOracleConnection()
}

private oracle.jdbc.internal.OracleConnection getConnection() throws SQLException {
String url = "jdbc:oracle:thin:@host:port/service_name”;
OracleDataSource ds = new OracleDataSource();
Properties prop = new Properties();
prop.setProperty("user","scott");
prop.setProperty("password","tiger");
ds.setConnectionProperties(prop);
ds.setURL(url);
oracle.jdbc.internal.OracleConnection conn =
(oracle.jdbc.internal.OracleConnection)ds.getConnection();
return conn;

}
}

也许使用 resultSet.getCLOB 而不是 resultSet.getClob。

关于java - oracle.sql.CLOB 无法转换为 oracle.sql.DatumWithConnection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49820519/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com