当前位置: 技术问答>java相关
查询数据库时的异常问题,高分请教。
来源: 互联网 发布时间:2015-04-16
本文导语: 系统输出如下: Line183 Line192 sqlbean.executeQuery:[Sybase][ODBC Driver][Adaptive Server Anywhere]Database server rejected connect ion: too many connections to database Line194 Line196 in LoginComponent.getComponentData(),catch SQLException. java.lang.NullPointerE...
系统输出如下:
Line183
Line192
sqlbean.executeQuery:[Sybase][ODBC Driver][Adaptive Server Anywhere]Database server rejected connect
ion: too many connections to database
Line194
Line196
in LoginComponent.getComponentData(),catch SQLException.
java.lang.NullPointerException
源码如下:
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 = con1.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();
con2.executeInsert(strSql);
con2.close();
System.out.println("Line209");
//向context中压值
context.setValue("group",group);
context.setValue("tie",tie);
}
rs1.close();
con.close();
}
catch(Exception esql){
System.out.println("in LoginComponent.getComponentData(),catch SQLException.");
System.out.println(esql);
}
请问这是什么原因?
Line183
Line192
sqlbean.executeQuery:[Sybase][ODBC Driver][Adaptive Server Anywhere]Database server rejected connect
ion: too many connections to database
Line194
Line196
in LoginComponent.getComponentData(),catch SQLException.
java.lang.NullPointerException
源码如下:
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 = con1.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();
con2.executeInsert(strSql);
con2.close();
System.out.println("Line209");
//向context中压值
context.setValue("group",group);
context.setValue("tie",tie);
}
rs1.close();
con.close();
}
catch(Exception esql){
System.out.println("in LoginComponent.getComponentData(),catch SQLException.");
System.out.println(esql);
}
请问这是什么原因?
|
too many connections to database//连接数太多
java.lang.NullPointerException//有空指针错误
读了你的程序,sqlbean的实例有 con、con1、con2
而在finally中关闭的仅con
也就是说,当空指针例外抛出时,有可能con1、con2的连接并没有正确关闭.
java.lang.NullPointerException//有空指针错误
读了你的程序,sqlbean的实例有 con、con1、con2
而在finally中关闭的仅con
也就是说,当空指针例外抛出时,有可能con1、con2的连接并没有正确关闭.