【发布时间】: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();
有人能解释一下为什么上面的代码不起作用吗?
【问题讨论】:
-
定义“错误”,定义“不工作”请阅读stackoverflow.com/help/how-to-ask
-
无法对表名进行参数化,请参阅stackoverflow.com/questions/7541761/…
-
我不建议像这样使用数据库进行内部化 - 相反,我会采用这种方法:docs.oracle.com/javase/tutorial/i18n/resbundle/index.html
-
这篇文章更多的是关于我所做的实际语法。我已经多次完成上述格式,除了这个表名是一个变量之外,我没有遇到任何问题。为什么表名变量会被区别对待?
-
因为它被包裹在''中