【问题标题】:SQL query works in MySQL but not in EclipseSQL 查询在 MySQL 中有效,但在 Eclipse 中无效
【发布时间】:2012-11-16 03:36:30
【问题描述】:

这个 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 follower.userid = " +
    userID +
    ")";

在控制台上打印:

从 twitter_content.userclient 中选择 userclient.username,其中 userclient.userid = (选择follower.followerid from twitter_content.follower where follower.followerid = userclient.userid 和follower.userid = 562570958)

此查询在直接在 MySQL 脚本中运行时有效,但在通过在 Eclipse 中运行的 Java 程序执行时无效。在 Eclipse 中运行时出现此异常:

 java.sql.SQLException: Column 'followerid' not found.

我已经有了表 Follower,其中包含 followerid 列。我该如何解决这个问题?

编辑:
UserClient 表有 2 列:用户 ID 和用户名。
Follower 表有 3 列:rowno、userid 和 followerid。

【问题讨论】:

  • 不熟悉 eclipse 但你需要确保它支持子查询才能在那里工作我知道 mysql 确实支持它
  • 两张表都有哪些列?
  • 请将两个表的 DDL 添加到您的问题中。另外,你为什么不使用 JOIN 而不是那个子选择?
  • 我在上面编辑过的帖子中描述了表格。
  • 你确定你真的在 mysql 和 Eclipse 中使用相同的数据库吗?

标签: java mysql eclipse


【解决方案1】:
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)

这行得通吗?

【讨论】:

    【解决方案2】:

    打印该查询并复制它。然后尝试在 mysql 中运行该查询。

    如果工作正常,则验证与数据库的连接。它可能正在连接到一个旧数据库,该数据库没有带有“followerid”的“Follower”表

    【讨论】:

      【解决方案3】:

      看起来你用点而不是逗号

      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_content

      【讨论】:

      • 不,我使用点来引用特定模式的表。
      猜你喜欢
      • 1970-01-01
      • 2015-10-21
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 1970-01-01
      相关资源
      最近更新 更多