实在搞不懂,这个遍历怎么显示的结果都不对!!1
<%!
String array22[] = new String[1000];
public void travel(int id,int num,String[] array) throws Exception
{
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft:sqlserver://192.168.235.33:1433;DatabaseName=XXX ";
String user= "sa ";
String password= "XXX ";
Connection conn= DriverManager.getConnection(url,user,password);
String sql= "select * from NS_ORGANIZATION where parent= "+id;
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
array[num++] = rs.getString( "name ");
if(rs.getString( "sonNum ")!= "0 ")
{
travel(rs.getInt( "id "),num,array);
}
}
rs.close();
stmt.close();
conn.close();
array22 = array;
}
%>
<%
String[] array =null;
array = new String[100];
travel(90,0,array);
for(int j=0;j <=20;j++)
{
out.print(array22[j]+ "haha <br> ");
}
数据库是这样的:
id name parent sonNum
90 网络办公室 0 4
91 XX 90 2
99 YY 90 2
100 ZZ 90 2
101 AA 90 2
102 XX1 91 0
103 XX2 91 0
104 YY3 99 0
105 YY4 99 0
106 ZZ1 100 0
107 ZZ2 100 0
108 AA1 101 0