private boolean InsertMmsBcc(List list){
String sqlbcc = "insert into mms_bcc(BCC_ID,BCC_NUMBER,MMS_ID) ";
String sqlcommit =  sqlbcc;
boolean bFlag = false;
for(int i=0;i<list.size();i++)
{
String tempStr = "select "+"bcc_id_seq.nextval,"+list.get(i)+","+m_MmsId + " from dual";
sqlcommit+=tempStr;
if(i+1 < list.size())
{
sqlcommit += " union ";
}
}
Connection conn =  DBConnectionManager.getInstance().getConnection("sjw"); 
Statement stmt=null;
try {
stmt = conn.createStatement();
stmt.executeUpdate(sqlcommit);
conn.commit();
bFlag = true;
} catch (SQLException e) {
System.out.println(e.getMessage());
}
catch(Exception e1)
{

}
if(stmt != null)
try {
stmt.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
DBConnectionManager.getInstance().freeConnection("sjw", conn);
return bFlag;
}
我程序就是这样调用的,数据库连接池,我是从网上拷贝的,
DBConnectionManager这个是管理数据类,代码如下回复

解决方案 »

  1.   

    http://xiaobian.javaeye.com/blog/111797
    数据库连接池管理类  是这个页面的代码
      

  2.   

    InsertMmsBcc这个方法是否被频繁的调用了??
    使用连接池,Connection关闭并不是物理关闭,只是归还连接池,所以PreparedStatement和ResultSet都被持有,并且实际占用相关的数据库的游标资源,在这种情况下,只要长期运行,往往就会报“游标超出数据库答应的最大值”的错误,导致程序无法正常访问数据库。
      

  3.   

    要关闭conn
        
      

  4.   

    InsertMmsBcc这个方法是否被频繁的调用了?? 
    使用连接池,Connection关闭并不是物理关闭,只是归还连接池,所以PreparedStatement和ResultSet都被持有,并且实际占用相关的数据库的游标资源,在这种情况下,只要长期运行,往往就会报“游标超出数据库答应的最大值”的错误,导致程序无法正常访问数据库。 
      

  5.   

    换PreparedStatement试试呢?另外把关闭和释放写到finally里
      

  6.   

    Java代码在执行conn.createStatement()和conn.prepareStatement()的时候,实际上都是相当与在数据库中打开了一个cursor。尤其是,假如你的createStatement和prepareStatement是在一个循环里面的话,就会非常轻易出现"游标超出数据库答应的最大值"。因为游标一直在不停的打开,而且没有关闭。createStatement和prepareStatement都应该要放在循环外面,而且使用了这些Statment后,及时关闭。
    try { 
        stmt = conn.createStatement(); 
        stmt.executeUpdate(sqlcommit);
        // 及时关闭
        stmt.close();
        conn.commit(); 
        bFlag = true; 
    } catch (SQLException e) { 
        System.out.println(e.getMessage()); 

      

  7.   

    会不会内存溢出了,这种情况将不会执行到你的关闭操作,最好是在执行commit后加个关闭.
    另外把InsertMmsBcc加成同步方法试试呢.