您好,下面这段代码,运行后,list集合打印出来是空数组【】,没有内容 显示。其中admin是mysql中的一张表,里面有用户信息。
```java
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import utils.JDBCUtils;
import java.sql.Connection;
import java.util.List;
public class DBUtils_USE {
public static void main(String[] args) throws Exception{
new DBUtils_USE().testQueryMany();
}
public void testQueryMany() throws Exception {
Connection connection = JDBCUtils.getConnection();
QueryRunner queryRunner = new QueryRunner();
String sql = "select `name` , pwd from admin where pwd = ? ";
List<Admin> list = queryRunner.query(connection, sql, new BeanListHandler<>(Admin.class),"'1234'");
System.out.println("list out as:");
for(Admin admin : list){
System.out.println(admin);
System.out.println("====");
}
System.out.println(list);
JDBCUtils.close(null,null,connection);
}
}
class Admin {
private String name;
private String pwd;
public Admin(String name, String pwd) {
this.name = name;
this.pwd = pwd;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
@Override
public String toString() {
return "Admin{" +
"name='" + name + '\'' +
", pwd='" + pwd + '\'' +
'}';
}
}
```