在Windows 8.1上使用Java 1.7.0.67准备好了一个问题...
基本上我得到如下错误(来自测试):
2014-08-17 16:56:37 org.help
SEVERE: Strt Testing
2014-08-17 16:56:37 org.help
SEVERE: Before pstText: SELECT "lineText" FROM "public"."dbText_?" WHERE "Textid" = '?'
2014-08-17 16:56:37 org.help
SEVERE: The column index is out of range: 1, number of columns: 0.
我可以看到它告诉我我没有?但他们可以在之前 setString消息中看到。
任何人都可以看到我正在做的事情有什么问题 - 我是PreparedStatements的新手,我认为这是正确的......
感谢和问候 肖恩
String zLocale = "en_EN";
PreparedStatement pst1 = null;
logger.severe("Strt Testing");
String sql1;
sql1= "SELECT \"lineText\" FROM \"public\".\"dbText_?\" WHERE \"Textid\" = \'?\';";
pst1 = con.prepareStatement(sql1);
logger.severe("Before pstText: "+ pst1.toString());
pst1.setString(1, "ABCDEF-001");
pst1.setString(2, zLocale);
logger.severe("After pstText: "+ pst1.toString());
logger.severe("Done Testing");
答案 0 :(得分:2)
您的查询应该像
String sql = "SELECT lineText FROM public.dbText_ABCDEF-001 WHERE Textid = ?";
此外,您不能为表名准备语句,因为它仅适用于列值