吊桶的方法:
String db;
for(int i=1;i<=100;i++){
if (i < 10) {
db = "00" + i;
}
else if (i >= 10 && i < 100) {
db = "0" + i;
}else{
db = "100";
}
HttpSession session = request.getSession();
session.setAttribute("db", db);
sflist = pnd.queryPhoneNumber(phoneNumber, request, response);
request.getSession().setAttribute("sflist", sflist);
}
实现类:: SF sf =null;
PreparedStatement ps=null;//
ResultSet resl=null;
Connection conn=null;
List<SF> sflist = new ArrayList<SF>();
try{
Class.forName("com.mysql.jdbc.Driver");
HttpSession session = request.getSession();
String db = (String)session.getAttribute("db");
System.out.println(db);
conn=DriverManager.getConnection("jdbc:mysql://192.168.20.236:3306/express"+db,"root" ,"123456");
System.out.println("链接:::"+"jdbc:mysql://192.168.20.236:3306/express"+db);
ps=conn.prepareStatement("select * from sf where f29=? or f30=? or f40=? or f41=?");
ps.setString(1, phoneNumber);
ps.setString(2, phoneNumber);
ps.setString(3, phoneNumber);
ps.setString(4, phoneNumber);
resl=ps.executeQuery();//返回查询的数量。
// 查询 的时候 一般都用while循环或者if循环;
while(resl.next()){
sf=new SF();
sf.setF1(resl.getString("f1"));
sf.setF2(resl.getString("f2"));
sf.setF3(resl.getString("f3"));
sf.setF4(resl.getString("f4"));
sf.setF5(resl.getString("f5"));
sflist.add(sf);
返回的sflist,我最后的效果是::每查询一个数据库,就在页面显示在当前数据库里面查到的符合条件的信息。。
但是现在是,它全部查完才一块显示。。而且只显示最后一个数据库查询到的信息。之前的被覆盖。。
怎么破!!
The code is too fragmented
sflist = pnd.queryPhoneNumber(phoneNumber, request, response); Is this new every time?
It’s too late, the background loop is so fast, even if it’s too late, it’s not necessary.
The data needs to be processed, encapsulated into classes, and then transmitted to the front desk through the network. The front desk must still traverse and parse.
Just check the database at once, and then return a list to the front desk. The front desk will make a list
table
and then loop through it and come back.Why do you have to check one item and display the other one?