有关bean里递归的问题? while循环中的createclasstree方法的返回值没接收,所以无论调用多少次,只是最外边的返回语句返回了值。而且还有疑问:只给str变量赋值为new String() ? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 String str="";if rs1.next()) str=rs1.getString("title") + createclasstree(rs1.getInt("id"));else return str; int i = 0;ArrayList str = new ArrayList();//这两句为全局变量public ArrayList createclasstree(int parentid) throws Exception { sql = "Select parent,id,title From classlist Where parent="+ parentid; ResultSet rs1 = dbconn.executeQuery(sql); //str[i]=new String(); while (rs1.next()) { str.add(rs1.getString("title")); createclasstree(rs1.getInt("id")); } rs1.close(); return str; } while (rs1.next()) { str += rs1.getString("title"); str += createclasstree(rs1.getInt("id"));} 用StringBuffer不要用String,StringBuffer是线程安全的while (rs1.next()) { str.append(rs1.getString("title")); str.append(createclasstree(rs1.getInt("id")));} 字符不多String就可以了,另外一个id有多少parent,用while直接将title连接不好吧,是不是要有连接符,如-public String createclasstree(int parentid) throws Exception { String sql = "Select parent,id,title From classlist Where parent="+ parentid; ResultSet rs1 = dbconn.executeQuery(sql); String str=""; while (rs1.next()) { str=rs1.getString("title"); str=str+createclasstree(rs1.getInt("id")); } rs1.close(); return str; } 为什么while (rs1.next()),只能循环一层呢?也就是rs1循环回来后没有记忆了! 看来你还没懂。因为你没有保存createclasstree方法的返回值,所以即使递归成功,也没有用。 关于Spring中的AOP和事物的源码剖析 关于连接池的应用 web工程的问题 初学者问个连sqlserver问题 求助一个简单问题 有没有用过花生壳+tomcat的,请教一下 struts时遇到的页面无法显示 100分求助图形统计报表 怎么用jsp实现网上邮件群发功能(有没有不用jmail的,或者更方便的)?急!!! 请问要iis也支持jsp应该怎么做? 急,这是怎么回事啊?大侠救命!!!!!!!! 简单问题!!在提交页面之前怎样判断其中一个text框中的内容是字符串还是数值串?
if rs1.next())
str=rs1.getString("title") + createclasstree(rs1.getInt("id"));
else
return str;
ArrayList str = new ArrayList();//这两句为全局变量
public ArrayList createclasstree(int parentid) throws Exception
{
sql = "Select parent,id,title From classlist Where parent="+ parentid;
ResultSet rs1 = dbconn.executeQuery(sql);
//str[i]=new String();
while (rs1.next())
{
str.add(rs1.getString("title"));
createclasstree(rs1.getInt("id"));
}
rs1.close();
return str;
}
{
str += rs1.getString("title");
str += createclasstree(rs1.getInt("id"));
}
{
str.append(rs1.getString("title"));
str.append(createclasstree(rs1.getInt("id")));
}
public String createclasstree(int parentid) throws Exception
{
String sql = "Select parent,id,title From classlist Where parent="+ parentid;
ResultSet rs1 = dbconn.executeQuery(sql);
String str="";
while (rs1.next())
{
str=rs1.getString("title");
str=str+createclasstree(rs1.getInt("id"));
}
rs1.close();
return str;
}