我用switch,case语句,不知道错哪了,请求帮助

bluesnow792003 2004-09-22 05:25:41
我用switch,case语句,
switch (searchType){
case '员工编号':
sql="select * from userType where userId='"+searchDemand+"'";
rs=sm.executeQuery(sql);
break;

case '员工姓名':
sql="select * from userType where name='"+searchDemand+"'";
rs=sm.executeQuery(sql);
break;

case '用户类型':
sql="select * from userType where type='"+searchDemand+"'";
rs=sm.executeQuery(sql);
break;

case '用户有效期':
sql="select * from userType where userDate<='"+searchDemand+"'";
rs=sm.executeQuery(sql);
break;

default:
break;
}
提示有错,可我不知道错哪了,请求帮助!谢谢!
...全文
223 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
edhappy 2004-09-22
  • 打赏
  • 举报
回复
xunyiren(从jsp开始) 说得对。这是很基础的问题,平时比较容易出错。
kill8108 2004-09-22
  • 打赏
  • 举报
回复
信xunyiren(从jsp开始)的啦,switch就只能支持这4种类型的
xinsiwuhen 2004-09-22
  • 打赏
  • 举报
回复
switch( SS )
{
case:......;break;
}
该语句中的"SS"只能为字符,不能为字符串或是数字!!1结论~~~~~~~~~~~````
xunyiren 2004-09-22
  • 打赏
  • 举报
回复
switch (searchType)==>searchType是(int,byte,short,char)中的一种....
ladofwind 2004-09-22
  • 打赏
  • 举报
回复
试了一下,确实不能用String类型的
ladofwind 2004-09-22
  • 打赏
  • 举报
回复
字符串也是用""号括起来啊
panzhiwei 2004-09-22
  • 打赏
  • 举报
回复
switch (searchType){
case '员工编号': 注意这里改为"员工编号"
sql="select * from userType where userId='"+searchDemand+"'";
rs=sm.executeQuery(sql);
break;

case '员工姓名':
sql="select * from userType where name='"+searchDemand+"'";
rs=sm.executeQuery(sql);
break;

case '用户类型':
sql="select * from userType where type='"+searchDemand+"'";
rs=sm.executeQuery(sql);
break;

case '用户有效期':
sql="select * from userType where userDate<='"+searchDemand+"'";
rs=sm.executeQuery(sql);
break;

default:
break;
}
qlyfe 2004-09-22
  • 打赏
  • 举报
回复
字符也可以的啊
kingfish 2004-09-22
  • 打赏
  • 举报
回复
switch (searchType) //只支持int,searchType应该是int(或能自动转型到int的,如byte,short,char)
JIEK_ONE 2004-09-22
  • 打赏
  • 举报
回复
楼上说的对
jinsfree 2004-09-22
  • 打赏
  • 举报
回复
case 后面只能是 字符 或者 数字,字符串不认吧

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧