[将变量放入Java字符串中以供mysql查询使用的方法,我们可以使用吗?在子查询中选择[重复项

问题描述 投票:-1回答:1

此问题已经在这里有了答案:

我想在子选择查询的mysql查询中插入Java字符串中的变量

 String cid=request.getParameter("cid");
 String sql2 ="select bname from brands where bid in ( Select bid from catbrand where cid = '"+ cid +"' )   ";
 ps =connection.prepareStatement(sql2);
 resultSet = ps.executeQuery(sql2);   
java jdbc
1个回答
0
投票
String cid=request.getParameter("cid");
String sql2 = "select bname from brands where bid in ( select bid from catbrand where cid=? )";
ps = connection.prepareStatement(sql2);
ps.setString(1, cid);
resultSet = ps.executeQuery();
© www.soinside.com 2019 - 2024. All rights reserved.