在嵌套的sql语句java中连接动态值
我试着寻找有关它的信息,但似乎没有关于它的例子
我有这样一句话:
long userID = user.getId();
String query = "select userclient.username from twitter_content.userclient where userclient.userid = " +
"(select follower.followerid from twitter_content.follower where follower.followerid = userclient.userid and follower.userid = "+userID+")";
但是Eclipse将“userID”读取为字符串,而不是变量。如何使Eclipse将“userID”作为变量读取
# 1 楼答案
最佳实践是使用PreparedStatement和占位符
?
的输入参数用法示例(来自JavaDocs):
将这个例子应用到你的案例中,你会得到如下结果: