0
近日筆者從GlassFish的3.1.1遷移到3.1.2,我在該行的GlassFish 3.1.2 - ResultSetWrapper40不能轉換到oracle.jdbc.OracleResultSet
oracle.sql.BLOB bfile = ((OracleResultSet) rs).getBLOB("filename");
得到了以下錯誤
java.lang.ClassCastException: com.sun.gjc.spi.jdbc40.ResultSetWrapper40 cannot be cast to oracle.jdbc.OracleResultSet
在以下程序:
public void fetchPdf(int matricola, String anno, String mese, String tableType, ServletOutputStream os) {
byte[] buffer = new byte[2048];
String query = "SELECT filename FROM "
+ tableType + " where matricola = " + matricola
+ " and anno = " + anno
+ ((tableType.equals("gf_blob_ced") || tableType.equals("gf_blob_car")) ? " and mese = " + mese : "");
InputStream ins = null;
//--------
try {
Connection conn = dataSource.getConnection();
//Connection conn = DriverManager.getConnection(connection, "glassfish", pwd);
java.sql.Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(query);
if (rs.next()) {
logger.info("select ok " + query);
oracle.sql.BLOB bfile = ((OracleResultSet) rs).getBLOB("filename");
ins = bfile.getBinaryStream();
int length;
while ((length = (ins.read(buffer))) >= 0) {
os.write(buffer, 0, length);
}
ins.close();
} else {
logger.info("select Nok " + query);
}
rs.close();
stmt.close();
//conn.close();
} catch (IOException ex) {
logger.warn("blob file non raggiungibile: "+query);
} catch (SQLException ex) {
logger.warn("connessione non riuscita");
}
}
我使用的是GlassFish連接池
@Resource(name = "jdbc/ape4")
private DataSource dataSource;
和JDBC/ape4資源屬於Oracle連接池具有以下PARAM
NetworkProtocol tcp
LoginTimeout 0
PortNumber 1521
Password xxxxxxxx
MaxStatements 0
ServerName server
DataSourceName OracleConnectionPoolDataSource
URL jdbc:oracle:thin:@server:1521:APE4
User glassfish
ExplicitCachingEnabled false
DatabaseName APE4
ImplicitCachingEnabled false
Oracle驅動程序是ojdbc6.jar,Oracle數據庫爲10g。
任何人都可以幫助我發生什麼?在Glassfish 3.1.1上工作正常。
謝謝。我關閉了JDBC對象包裝,但也必須將DataSourceName從OracleConnectionPoolDataSource轉換爲OracleDataSource,將資源類型轉換爲javax.sql.DataSource而不是javax.sql.ConnectionPoolDataSource。使用不同資源類型會產生什麼後果? – maxqua72
@ maxqua72爲什麼不使用JDBC標準方法。你的代碼中沒有任何東西需要你使用Oracle特定的方法。 –
是的,我會但我想明白。你的回答解決了我的問題,但我仍然有漏洞來填補我對這個主題的認識。謝謝。 – maxqua72