1个回答
展开全部
public List SearchAll(){
List l = new ArrayList();
EmployeeBean ea = null;
ResultSet rs = null;
PreparedStatement ps = null;
Connection con = null;
sql = "select * from Employee";
try {
con = BaseDAO.GetConnection();
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
ea = new EmployeeBean();
ea.setId(rs.getInt(1));
ea.setDerpartId(rs.getInt(2));
ea.setName(rs.getString(3));
ea.setPassword(rs.getString(4));
l.add(ea);
}
你看一下我这个例子
List l = new ArrayList();
EmployeeBean ea = null;
ResultSet rs = null;
PreparedStatement ps = null;
Connection con = null;
sql = "select * from Employee";
try {
con = BaseDAO.GetConnection();
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
ea = new EmployeeBean();
ea.setId(rs.getInt(1));
ea.setDerpartId(rs.getInt(2));
ea.setName(rs.getString(3));
ea.setPassword(rs.getString(4));
l.add(ea);
}
你看一下我这个例子
追答
你定义一个实体类。我这个采用的是JavaBean+SQL做的,也就是所有结果使用实体类传值,add直接转入实体类
package test;
public class EmployeeBean {
private Integer id;
private Integer derpartId;
private String name;
private String password;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getDerpartId() {
return derpartId;
}
public void setDerpartId(Integer derpartId) {
this.derpartId = derpartId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
这个是我的实体类代码,你注意一下你数据库中字段和字段类型varchar型使用String类型封装
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询