public List getAllNotice(){
Connection con=null;
PreparedStatement stm=null;
ResultSet rs=null;
List list=new ArrayList();
try{
con=ConnectionManager.getConnection();
String sql="select * from notice where ntype=?";
stm=con.prepareStatement(sql);
rs=stm.executeQuery();
while(rs.next()){
int no=rs.getInt("Nno");
String title=rs.getString("Ntitle");
Notice notice=new Notice(no);
notice.setId(no);
notice.setTitle(title);
list.add(notice);
}
}catch(Exception e){
e.printStackTrace();
}finally{
ConnectionManager.closeResultSet(rs);
ConnectionManager.closeStatement(stm);
ConnectionManager.closeConnection(con);
}
return list;
}
这个问题出在哪里了?
String sql="select * from notice where ntype=?";
stm=con.prepareStatement(sql);
stm.setInt(1, 参数); //给ntype一个参数
stm=con.prepareStatement(sql);
String type = "xxx";//设置要查询的type的值
stm.setString(1,type);//如果是Int类型则用setInt方法;
rs=stm.executeQuery();