自己定义了一个递归读数据库的函数:
<%!
void getNewsClass(Writer w,String pId) throws Exception
... {
try...{
DB tempdb=new DB();
String sql="select * from Class where p_ID="+pId+" order by c_id asc";
ResultSet temprs=tempdb.exeQuery(sql);
while(temprs.next())...{
String cid=temprs.getString("c_id");
String cname=temprs.getString("c_name");
w.write(cid+cname+"<br>");
w.flush();
getNewsClass(w,temprs.getString("c_id"));
}
temprs.close();
tempdb.closeDB();
}catch(Exception e)...{
System.out.println(e.getMessage());
}
}
%>
void getNewsClass(Writer w,String pId) throws Exception
... {
try...{
DB tempdb=new DB();
String sql="select * from Class where p_ID="+pId+" order by c_id asc";
ResultSet temprs=tempdb.exeQuery(sql);
while(temprs.next())...{
String cid=temprs.getString("c_id");
String cname=temprs.getString("c_name");
w.write(cid+cname+"<br>");
w.flush();
getNewsClass(w,temprs.getString("c_id"));
}
temprs.close();
tempdb.closeDB();
}catch(Exception e)...{
System.out.println(e.getMessage());
}
}
%>
老出问题,不能执行数据库的递归读取,改为如下:
<%!
void getNewsClass(Writer w,String pId) throws Exception
... {
try...{
DB tempdb=new DB();
String sql="select * from Class where p_ID="+pId+" order by c_id asc";
ResultSet temprs=tempdb.exeQuery(sql);
while(temprs.next())...{
String cid=temprs.getString("c_id");
String cname=temprs.getString("c_name");
w.write(cid+cname+"<br>");
w.flush();
getNewsClass(w,cid);
}
temprs.close();
tempdb.closeDB();
}catch(Exception e)...{
System.out.println(e.getMessage());
}
}
%>
void getNewsClass(Writer w,String pId) throws Exception
... {
try...{
DB tempdb=new DB();
String sql="select * from Class where p_ID="+pId+" order by c_id asc";
ResultSet temprs=tempdb.exeQuery(sql);
while(temprs.next())...{
String cid=temprs.getString("c_id");
String cname=temprs.getString("c_name");
w.write(cid+cname+"<br>");
w.flush();
getNewsClass(w,cid);
}
temprs.close();
tempdb.closeDB();
}catch(Exception e)...{
System.out.println(e.getMessage());
}
}
%>
就没有问题了,不知道为什么?(红色代码为修改处)