我从数据库查询数据,然后将blob数据转换为字符串,但发生了异常:
java.sql.SQLException:ORA-01000:超出最大打开游标数
ORA-01000: maximum open cursors exceeded
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.v8TTILob.receiveReply(v8TTILob.java:991)
at oracle.jdbc.ttc7.v8TTILob.getChunkSize(v8TTILob.java:347)
at oracle.jdbc.ttc7.TTC7Protocol.getLobChunkSize(TTC7Protocol.java:3091)
at oracle.sql.LobDBAccessImpl.getChunkSize(LobDBAccessImpl.java:334)
at oracle.sql.BLOB.getChunkSize(BLOB.java:484)
at oracle.sql.BLOB.getBufferSize(BLOB.java:521)
at oracle.sql.BLOB.getBinaryStream(BLOB.java:256)
at weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB.getBinaryStream(Unknown Source)
at com.creationstar.bjtax.qsgl.BizLogic.dao.clfgl.FwxxDAO.convertBlobToString(FwxxDAO.java:138)
at com.creationstar.bjtax.qsgl.BizLogic.dao.clfgl.FwxxDAO.queryFwList(FwxxDAO.java:379)
at com.creationstar.bjtax.qsgl.BizLogic.processor.clfgl.ClfxxcjProcessor.getCjxx(ClfxxcjProcessor.java:473)
at com.creationstar.bjtax.qsgl.BizLogic.processor.clfgl.ClfjyxxCXProcessor.doQuery(ClfjyxxCXProcessor.java:173)
at com.creationstar.bjtax.qsgl.BizLogic.processor.clfgl.ClfjyxxCXProcessor.process(ClfjyxxCXProcessor.java:50)
代码是这样的:
public ArrayList queryFwList(String conditions)
throws SQLException {
ArrayList fwxxList = new ArrayList();
String sql = "select sbbh,htbh,fwcqzh,fwsyqztfrq,fwzlqx,fwzldz,fwjzmj,jzjgdm,ghyt,fwqszylx,zcs,szlc,htwsqyrq,sfwscsssggf,htzj,bzdm,bzmc,hl,wbje,fdczjjgmc,bbbs,swjgzzjgdm,sfesf,cjr,cjrq,lrr,lrrq,bz,ewmsj,FWXZDM,xxly from qsdb.qs_jl_fwxxb "
+ conditions;
Debug.out("queryFwList:" + sql);
Connection conn=null;
PreparedStatement ps = null;
try {
try {
conn = QSDBUtil.getConnection();
} catch (BaseException e) {
e.printStackTrace();
}
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Fwxx fwxx = new Fwxx();
fwxx.setSbbh(rs.getString("sbbh"));
...
...
if (rs.getBlob("ewmsj") != null
&& !"".equals(rs.getBlob("ewmsj"))) {
fwxx.setEwmsj(convertBlobToString(rs.getBlob("ewmsj")));
}
fwxx.setFwxzdm(rs.getString("FWXZDM"));
fwxx.setXxly(rs.getString("xxly"));
fwxxList.add(fwxx);
}
System.out.println(" FwxxList size:" + fwxxList.size());
rs.close();
} catch (SQLException e) {
e.printStackTrace();
throw e;
} finally {
ps.close();
QSDBUtil.freeConnection(conn);
}
return fwxxList;
}
//将Blob转换为字符串的代码。
public String convertBlobToString(Blob blob) {
String result = "";
try {
InputStream inStream = (InputStream) blob.getBinaryStream();
if (blob != null)
try {
byte[] data = new byte[200];
int length = 0;
while ((length = inStream.read(data, 0, 200)) != -1) {
String str = new String(data, 0, length);
result = result + str;
}
inStream.close();
} catch (Exception e) {
e.printStackTrace();
}
} catch (SQLException e) {
e.printStackTrace();
}
return result;
}