preparedstatement在sql语句中间的?怎么不能这样用,
Stringsql="select*fromtb_location1where1andUID=?orderbyiddesclimit0,1";PreparedStatem...
String sql = "select * from tb_location1 where 1 and UID = ? order by id desc limit 0,1";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1, str.trim());出错,说是SQL语句在?处 展开
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1, str.trim());出错,说是SQL语句在?处 展开
1个回答
展开全部
你是要给pstmt中的参数(UID)赋值,为何用sql啊?
那不是成了:
select *
from tb_location1
where 1
and UID = select * from tb_location1 where 1 and UID = ? order by id desc limit 0,1
order by id desc limit 0,1
追问
patmt.setString(1,str.trim());
是str,自己的字符串,不是sql这个字符串!!!
追答
结果串都已经给出了,你没有看懂?
你应该pstmt.setString(1, strUID) --变量名不对!!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询