String temp=123;

String s= "select intID from ipr_navtable where intParentID=(?)"; // 

while(!temp.equals(""))
{
delString+=temp;

try
{
preparedstatement = connection.prepareStatement(s);
preparedstatement.setString(1, temp);
resultset = preparedstatement.executeQuery();
preparedstatement.close();
}
catch(SQLException sqlexception)
{
resultset.close();
preparedstatement.close();
DBConnect.closeConnection(connection);
}

temp="";
 while(resultset.next());
{
temp+=","+String.valueOf(resultset.getInt("intID"));
}
}上面是为了找一个点的所有孩子节点 的部分代码
大家看看是在哪里错了
竟然出现java.lang.OutOfMemoryError: Java heap space
错误

解决方案 »

  1.   

    第一,只要SQL的结构没有变化,变的只是?的内容,那么一个PreparedStatement足矣,因此放到while外面prepare/close,只需在while里setString第二,永远不要在循环中使用+来拼接String还有,假设n+1是n的儿子你10的纪录是不是
    intID "10"
    intParentID "1,2,3,4,5,6,7,8,9,"SQL:select intID from ipr_navtable where intParentID='1,2,3,4,5,6,7,8,9,';
     ?????!!!!!晕到极致!!!!!
      

  2.   

    对不起,看错了,反正没有看懂,为什么,下面一次查询的记录需要上一次的n个ID作为parentID?
      

  3.   

    我发现了一处错误  while(resultset.next());
    应该把;去掉
    但是 去了后还是有错误
      

  4.   

    “对不起,看错了,反正没有看懂,为什么,下面一次查询的记录需要上一次的n个ID作为parentID?”我是这么想的1 有2,3,4 三个儿子
    那么在下次查询中就要把2, 3, 4 作为父亲(1) 放入temp中2 有5,6 
    3 有7,8
    4 有9,10那么temp 就 成了5, 6 ,7 ,8,9,10
    如此下去找到所有的 1的孩子节点
      

  5.   

    try语句放到循环体外面,基本常识另外,如果很耗资源,调节一下jvm堆的大小
      

  6.   

    “try语句放到循环体外面,基本常识  另外,如果很耗资源,调节一下jvm堆的大小”我什么都不懂 
    请问jvm堆是什么
    怎么调解呀
      

  7.   

    找到了很多错误 改了之后还是有点问题
    就是 当查到1287的孩子1288 1290 1291 
    temp在查询前变成了(1288,1290,1291)
    但是1288的还在1292 就 查不到了问题出在哪里了int intID=1287;

    connection = DBConnect.getConnection();
    String delString="";
    String temp=String.valueOf(intID);
    String s= "select intID from ipr_navtable where intParentID in (?)"; // 

    while(!temp.equals(""))
    {


    preparedstatement = connection.prepareStatement(s);
    preparedstatement.setString(1, temp);
    resultset = preparedstatement.executeQuery();
    preparedstatement.close();


    temp="";
     while(resultset.next())
    {
    temp+=String.valueOf(resultset.getInt("intID"))+",";
    }
    delString+=temp;
    if(temp.length()>0)
    temp=temp.substring(0,temp.length()-1);

    }

    delString=delString.substring(0,delString.length()-1);
    DBConnect.closeConnection(connection);%>