Java SQL查询在MySQL中工作,但在Eclipse中不工作
此SQL查询:Java SQL查询在MySQL中工作,但在Eclipse中不工作,java,mysql,eclipse,Java,Mysql,Eclipse,此SQL查询: 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
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 +
")";
在控制台上打印:
从twitter_content.userclient中选择userclient.username,其中
userclient.userid=从中选择follower.followerid
twitter\u content.follower其中follower.followerid=userclient.userid
和follower.userid=562570958
当直接在MySQL脚本中运行时,此查询有效,但当通过在Eclipse中运行的Java程序执行时,此查询无效。在Eclipse中运行时,我会遇到以下异常:
java.sql.SQLException: Column 'followerid' not found.
我已经有了表跟随器,其中包含followerid列。我如何解决这个问题
编辑:
UserClient表有两列:userid和username。
Follower表有3列:rowno、userid和followerid。看起来像是用点而不是逗号
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 = 562570958)
也不确定为什么在子查询from子句中有twitter_内容
select userclient.username
from twitter_content.userclient as userclient
where userclient.userid =
(select follower.followerid
from twitter_content.follower as follower
where follower.followerid = userclient.userid and follower.userid = 562570958)
这行吗?打印并复制该查询。然后尝试在mysql中运行该查询
如果工作正常,则验证与数据库的连接。它可能连接到一个旧的数据库,该数据库没有“Follower”表和“followerid”不熟悉eclipse,但您需要确保它支持子查询,以便在那里工作。我知道mysql确实支持它。两个表中都有哪些列?请将两个表的DDL添加到您的问题中。另外,为什么不使用连接而不是子选择?我在上面编辑的文章中描述了这些表。你确定在mysql和Eclipse中使用的是同一个数据库吗?不,我使用点来引用特定模式的表。