>>too many connections to database
写得不是很明显吗? 你程序中取得太多的 connection 了, 一个连接可以做多次操作的.

解决方案 »

  1.   

    这段程序有个BUG,就是当程序抛例外时,已建立的连接无法正常释放,造成连接数过多,而无法再连接数据库。在catch后加上:finally{
        rs1.close();
        con.close();
                          
    }
      

  2.   

    我把程序改成:
    sqlbean con = new sqlbean();
                                String strSql = "select * from dgkt_user where name='" + uid + "'";
                                try{
                                    ResultSet rs1 = con.executeQuery(strSql);
                                   
                                    //表dgkt_user中没有此用户,则新增一条记录。tie(权限)从dgkt_groupTie中取得。
                                    if (!rs1.next())
                                    {
                                        String group = "";
                                        //insert code here to use uid get group
                                        group = "用户组一";
                                        strSql = "select tie from dgkt_groupTie where groupName='" + group + "'";
                                        System.out.println("Line192---");
                                        //sqlbean con1 = new sqlbean();
                                        ResultSet rs2 = con.executeQuery(strSql);
                                        System.out.println("Line194---");
                                        String tie = "";
                                        System.out.println("Line196---");
                                        if (rs2.next())
                                        {
                                            tie = rs2.getString("tie");
                                        }else{
                                            System.out.println("表dgkt_groupTie中的数据有误,请检查后更正。");
                                        }
                                        System.out.println("Line203");
                                        rs2.close();
                                        //con1.close();
                                        //向dgkt_user表中插入该记录
                                        strSql = "Insert into dgkt_user(name,tie,pw,nick,privacy)values('" + uid + "','" + tie + "','" + pwd + "','未知','未知')";
                                        System.out.println("Line207");
                                        //sqlbean con2 = new sqlbean();
                                        con.executeInsert(strSql);
                                        //con2.close();
                                        System.out.println("Line209");
                                        //向context中压值
                                        context.setValue("group",group);
                                        context.setValue("tie",tie);
                                    }
                                }
                                catch(Exception esql){
                                    System.out.println("in LoginComponent.getComponentData(),catch SQLException.");
                                    System.out.println(esql);
                                }
                                finally
                                {
                                    rs1.close();
                                    con.close();
                                }
    依然报同样的错误,为什么?
      

  3.   

    另外,rs1不能在finally中关闭,因为它是在try中定义的,在finally中无法访问。
      

  4.   

    too many connections to database//连接数太多
    java.lang.NullPointerException//有空指针错误读了你的程序,sqlbean的实例有 con、con1、con2而在finally中关闭的仅con也就是说,当空指针例外抛出时,有可能con1、con2的连接并没有正确关闭.