主题:请帮忙看看我的程序怎么总是抛出“ORA-01000: 超出打开游标的最大数”异常
我的程序的部分代码为:
Connection con = null;
//Statement stmt =null;
PreparedStatement pstmt = null;
ResultSet rstm = null;
ResultSet rs = null;
String url = urlRoot + dbName;
try {
Class.forName(jdbcDriver);
DriverManager.registerDriver(new OracleDriver());
con = DriverManager.getConnection(url, user, password);
con.setAutoCommit(false);
while((s = in.readLine()) != null){
if(s.contains(">")){
if(s.contains("|") & s.contains("- "))
{
int begin = s.indexOf("|");
int end = s.lastIndexOf("- ");
proID = s.substring(0, begin).trim();
abstractFunction = s.substring((begin + 1), end).trim();
organism = s.substring((end + 1)).trim();
}
}
else {
sequense = s;
if(proID != "" & sequense != "" ){
try{
CLOB clob = null;
if(pstmt == null)
pstmt = con.prepareStatement("select proid from maliky_first.uniproswiss where proid = ?");
pstmt.setString(1, proID);
rstm = pstmt.executeQuery();
if (!rstm.next()){
pstmt.close();
pstmt = null;
pstmt = con.prepareStatement("INSERT INTO maliky_first.uniproswiss (proid,sequense,abstractfunction,organism) VALUES(?,empty_clob(),?,?)");
pstmt.setString(1,proID);
pstmt.setString(2,abstractFunction);
pstmt.setString(3,organism);
pstmt.executeUpdate();
pstmt.close();
pstmt = con.prepareStatement("select sequense from maliky_first.uniproswiss where proid= ? for update");
pstmt.setString(1,proID);
rs = pstmt.executeQuery();
if (rs.next()) clob = (CLOB) rs.getClob(1);
rs.close();
pstmt = con.prepareStatement("update maliky_first.uniproswiss set sequense=? where proid=?");
Writer out = clob.getCharacterOutputStream();
out.write(sequense);
out.close();
pstmt.setClob(1,clob);
pstmt.setString(2,proID);
pstmt.executeUpdate();
pstmt.close();
}
rstm.close();
pstmt.close();
}catch(SQLException e){
System.out.println(proID);
System.err.println(e.getMessage());
System.err.println(e.getLocalizedMessage());
}finally{
try
{
if (pstmt != null)
pstmt.close();
}
catch(Exception e) {}
try
{
if (rs != null)
rs.close();
}
catch(Exception e) {}
try
{
if (rstm != null)
rstm.close();
}
catch(Exception e) {}
pstmt = null;
rs = null;
rstm = null;
}
}
}
}
con.commit();
con.close();
} catch (ClassNotFoundException e) {
System.err.println(e.getMessage());
}catch(SQLException e){
System.err.println(e.getMessage());
}finally{
try
{
if (pstmt != null)
pstmt.close();
}
catch(Exception e) {}
try
{
if (con != null)
con.close();
}
catch (Exception e){}
try
{
if (rs != null)
rs.close();
}
catch(Exception e) {}
try
{
if (rstm != null)
rstm.close();
}
catch(Exception e) {}
}
}
Connection con = null;
//Statement stmt =null;
PreparedStatement pstmt = null;
ResultSet rstm = null;
ResultSet rs = null;
String url = urlRoot + dbName;
try {
Class.forName(jdbcDriver);
DriverManager.registerDriver(new OracleDriver());
con = DriverManager.getConnection(url, user, password);
con.setAutoCommit(false);
while((s = in.readLine()) != null){
if(s.contains(">")){
if(s.contains("|") & s.contains("- "))
{
int begin = s.indexOf("|");
int end = s.lastIndexOf("- ");
proID = s.substring(0, begin).trim();
abstractFunction = s.substring((begin + 1), end).trim();
organism = s.substring((end + 1)).trim();
}
}
else {
sequense = s;
if(proID != "" & sequense != "" ){
try{
CLOB clob = null;
if(pstmt == null)
pstmt = con.prepareStatement("select proid from maliky_first.uniproswiss where proid = ?");
pstmt.setString(1, proID);
rstm = pstmt.executeQuery();
if (!rstm.next()){
pstmt.close();
pstmt = null;
pstmt = con.prepareStatement("INSERT INTO maliky_first.uniproswiss (proid,sequense,abstractfunction,organism) VALUES(?,empty_clob(),?,?)");
pstmt.setString(1,proID);
pstmt.setString(2,abstractFunction);
pstmt.setString(3,organism);
pstmt.executeUpdate();
pstmt.close();
pstmt = con.prepareStatement("select sequense from maliky_first.uniproswiss where proid= ? for update");
pstmt.setString(1,proID);
rs = pstmt.executeQuery();
if (rs.next()) clob = (CLOB) rs.getClob(1);
rs.close();
pstmt = con.prepareStatement("update maliky_first.uniproswiss set sequense=? where proid=?");
Writer out = clob.getCharacterOutputStream();
out.write(sequense);
out.close();
pstmt.setClob(1,clob);
pstmt.setString(2,proID);
pstmt.executeUpdate();
pstmt.close();
}
rstm.close();
pstmt.close();
}catch(SQLException e){
System.out.println(proID);
System.err.println(e.getMessage());
System.err.println(e.getLocalizedMessage());
}finally{
try
{
if (pstmt != null)
pstmt.close();
}
catch(Exception e) {}
try
{
if (rs != null)
rs.close();
}
catch(Exception e) {}
try
{
if (rstm != null)
rstm.close();
}
catch(Exception e) {}
pstmt = null;
rs = null;
rstm = null;
}
}
}
}
con.commit();
con.close();
} catch (ClassNotFoundException e) {
System.err.println(e.getMessage());
}catch(SQLException e){
System.err.println(e.getMessage());
}finally{
try
{
if (pstmt != null)
pstmt.close();
}
catch(Exception e) {}
try
{
if (con != null)
con.close();
}
catch (Exception e){}
try
{
if (rs != null)
rs.close();
}
catch(Exception e) {}
try
{
if (rstm != null)
rstm.close();
}
catch(Exception e) {}
}
}