【问题标题】:MySQL Query in Java EclipseJava Eclipse 中的 MySQL 查询
【发布时间】:2015-06-22 23:50:38
【问题描述】:

我正在编写一个程序,用户将在其中接收不同语言的指令。我有按语言划分的表结构,因此根据用户的语言用户设置,将选择相应的语言表。但是,我不断从以下代码中收到错误。

            String query2 = "select * from ? where instruction_id = ?";
            PreparedStatement pst2 = connection.prepareStatement(query);
            pst2.setString(1, user_config.language);
            pst2.setString(2, instruction_id);
            ResultSet rs2 = pst2.executeQuery();

有人能解释一下为什么上面的代码不起作用吗?

【问题讨论】:

标签: java mysql eclipse


【解决方案1】:

我最终对表名使用了字符串连接。

      String query2 = "select * from " + user_config.language + " where instruction_id = ?";
      PreparedStatement pst2 = connection.prepareStatement(query2);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-26
    • 2014-09-29
    • 2015-04-15
    • 1970-01-01
    • 2013-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多