当前位置: 代码迷 >> Java Web开发 >> JSP 里SQL语句怎么使用"与"把两个条件输出来?
  详细解决方案

JSP 里SQL语句怎么使用"与"把两个条件输出来?

热度:6676   发布时间:2013-02-25 21:11:08.0
JSP 里SQL语句如何使用"与"把两个条件输出来???
String sql = "select * from category where grade = 2 and 3";

grade有三级,我想把2,3级的数据全部输出来,可是为什么只能输出2级的,3的出不来
-------------------------------------------------------------------------
public List<Category> getChilds(){
List<Category>categories = new ArrayList<Category>();
Connection conn=DB.getConn();
Statement stmt = DB.getStatement(conn);
String sql = "select * from category where grade = 2 and 3";
ResultSet rs = DB.getResultSet(stmt, sql);
try{
while(rs.next()){
Category c = this.getCategoryFromRs(rs);
categories.add(c);
}
}catch(SQLException e){
e.printStackTrace();
}finally{
DB.close(conn);
DB.close(stmt);
DB.close(rs);
}
return categories;
}
-----------------------------
<%
for(int i=0;i<childs.size();i++){
Category c = childs.get(i);
%>
<a href=""><%=c.getName()%></a>
<%

%>

------解决方案--------------------------------------------------------
同一个条件也要分开单独写, where grade=2 and grade=3
------解决方案--------------------------------------------------------
探讨

同一个条件也要分开单独写, where grade=2 and grade=3

------解决方案--------------------------------------------------------
SQL code
select * from category where grade = 2 or 3
  相关解决方案