JavaEE课程设计中遇到的问题,求大神指点:
java web
代码如下:
public String Query(HttpServletRequest request){
String html="";
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String type=request.getParameter("type");
String content=request.getParameter("content");
String sql="select * from tellist where '"+type+"'='"+content+"'";
try{
Statement pstmt=con.createStatement();
ResultSet rs1=pstmt.executeQuery(sql);
html+="
";
html+="";
while(rs1.next()){
html+="
html+="</table>";
}
catch(Exception e){
e.printStackTrace();
}
return html;
}
在查询页面一个下拉框,一个表单,下拉框的值是表tellist中的name,sex,age,tel,
,mail,adr字段。下拉框选中查询类型,表单传送查询内容。运行过程没有报错,但是除了表格第一行能输出,while(rs1.next())中的没有执行,查了半天都没查处问题在哪里,求大神指点
debug一下你会发现rs里面并没有值,是你的sql的问题。, type不要使用''(单引号)或者使用·(键盘数字键1左边的那个)