日期:2014-05-18  浏览次数:20622 次

jsp语句中的变量如何添加''和+号?
select   *   from   usertable   where   usercode= 'username '   and   activeflag=y
其中username是从页面中取值的变量

------解决方案--------------------
String str= "select * from usertable where usercode= ' "+username+ " ' and activeflag= 'y ' ";
ResultSet rs=stmt.executeQuery(str);
activeflag=y 是sql变量还是其它?
------解决方案--------------------
俺来教你。
首先坐好
比如这一句
String sql== "select * from usertable where usercode= ' "+username+ " ' and activeflag=y "
out.println(sql);去掉左右两边的双引号放到数据中去查一下就知道对错了

一般username是数据库中的字段是字符串类型,y是整形