JSP中的数据库查询

来源:百度知道 编辑:UC知道 时间:2024/04/23 17:22:55
我用一个变量保存了要数据库中的"编号"字段的一个值,在SQL语句中怎么用这个变量?
如: rs = sql1.executeQuery("select * from table1 where 编号 = ________");
问题:上面的_______怎么写?
________是int型的.

rs = sql1.executeQuery("select * from table1 where 编号 ="+变量名);
这样写就可以了
如果编号是字符型那就得这样写
rs = sql1.executeQuery("select * from table1
where 编号 ='"+变量名+"'");

int iBianHao;
rs = sql1.executeQuery("select * from table1 where 编号 = "+iBianHao);
String strBianHao
rs = sql1.executeQuery("select * from table1 where 编号 = '"+strBianHao+"'");