java PreparedStatement ResultSet 的数据库问题
//显示职工表所有记录
public List<person> Search() throws SQLException{
Connection conn = sjk2.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select Eno,Cno,En,Sex,Etitle,Eage,Esal from zhigong");
List<person> people = new ArrayList<person>();
person p = null;
while(rs.next()){//如果对象中有数据,就会循环打印出来
p = new person();
p.setEno(rs.getString("Eno"));
p.setCno(rs.getString("Cno"));
p.setEn(rs.getString("En"));
p.setSex(rs.getString("Sex"));
p.setEtitle(rs.getString("Etitle"));
p.setEage(rs.getInt("Eage"));
p.setEsal(rs.getInt("Esal"));
people.add(p);
}
return people;
}
目前的问题是,我想单独查询表中符合某条件 带参数(“Eno=?”)的数据集
想替换 加这一句("select Eno,Cno,En,Sex,Etitle,Eage,Esal from zhigong where Eno=?") 加上去后系统提示语法有错误
请问应该怎么修改
这个是带参数的另一个 可以运行,主要问题是不会结合ResultSet 求大神指导 谢谢~
//delete
public void SearchOne(String Eno) throws SQLException{
person p = null;
Connection conn=sjk2.getConnection();
String sql="" +
"delete from zhigong where Eno = ?";
PreparedStatement psmt = conn.prepareStatement(sql);
psmt.setString(1,Eno);
//执行SQL语句
psmt.execute();
}