The code in question is as follows:
public ArrayList<menuentity> getMenuList(Connection con){
ArrayList<menuentity> list=null;
try {
String sql="select * from menu where misEnable=1";
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
System.out.println("rs:"+rs);
menuentity m=null;
list=new ArrayList<menuentity>();
System.out.println("new ArrayList<menuentity>();");
while(rs.next()){
System.out.println("rs.next()");
m=new menuentity();
m.setMid(rs.getString(1));
m.setMname(rs.getString(2));
m.setMurl(rs.getString(3));
m.setMimg(rs.getString(4));
m.setMparnetid(rs.getString(5));
m.setMcreatedate(rs.getDate(6));
m.setMisEnable(rs.getInt(7));
m.setMcreater(rs.getString(8));
m.setMisLeaf(rs.getInt(9));
System.out.println("1:"+rs.getString(1));
list.add(m);
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("1daolist:"+list);
return list;
}
Phenomenon description: This method can be executed to System.out.println("new ArrayList<menuentity>();");, but it is not executed in the while loop because System.out.println("rs.next ()"); There is no output in the console, but the SQL statement can find the data in the database, and there is no problem with the connection passed in by the method, because another page and this method use a connection together, and the other page can be returned from the background Data,
This is debugged by contacting tomcat in eclipse
Question: Why is there no execution in while? What may be the reason? Thanks! ! !
我想大声告诉你2017-05-17 10:09:26
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
Isn’t this written correctly?
Try writing it like this
Statement stmt=con.createStatement(sql);
ResultSet rs=stmt.executeQuery();