我这段代码实现插入数据,但会抛出 "can't found free connection" 的异常,一直找不到解决的办法啊``
希望高手指点出错误所在!谢谢`#define INSERTSQL "insert into SystemTab(TableId,Key1,Key2,Key3,Key4) values(?,?,?,?,?)"
void SystemTabManager::insert(int pkey1, int TabId)
{
     DBConnection* conn=NULL;
    SystemTab* pSystemTab=NULL;
    try
    {        
             SystemTab::TABLE temp;
             temp.key.Key1=pkey1;
             temp.key.TableId=TabId;
             temp.Key2=1;
             conn=&(DBConnectionFactory::getIntance()->getConnection());
             Statement& stmt=conn->createDyncStatement(INSERTSQL); 
            
            
             int pos=0;
             stmt.setParam(pos++, temp.key.TableId);
             stmt.setParam(pos++, temp.key.Key1);
             stmt.setParam(pos++, temp.Key2); 
                      
             stmt.execute();
             SystemTab::TABLE tabsystemtab=temp;
             tabsystemtab.key.Key1=temp.key.Key1;
             pSystemTab=new SystemTabImpl(tabsystemtab);
             
             conn->close();
    
    }
    catch (DatabaseException e)
    {   
        
        if(conn)
            conn->close();
    }}

解决方案 »

  1.   

    检查connection是否有类似open这样的方法,执行查询前需要先打开连接。
      

  2.   

    检查 getConnection 中是否正确连接上数据库
      

  3.   

    是数据库没有连接上,后面我调试了,改正回来了!但又有新的问题出来了
    又抛出异常:exception {_m_what=0x076c0968 "INSERT INTO 语句的语法错误。" _m_doFree=1 }我仔细检查了插入语句(#define INSERTSQL "insert into SystemTab(TableId,Key1,Key2,Key3,Key4) values(?,?,?,?,?)"
    )应该没有语法错误啊!我想问问各位高手还有什么其他原因影响了插入语法?
      

  4.   

    试试“insert into SystemTab([TableId],[Key1],[Key2],[Key3],[Key4]) values(?,?,?,?,?)”
    应该是关键字的问题!
      

  5.   

    谢谢topattack 帮忙!就是那个错误!!总算解决了! 
               我结贴了!!
                        再次祝福楼上各位大大 牛年走大运 牛气冲天