Windows 8.1上使用Java 1.7.0.67的preparestatement出现问题...
基本上我得到如下错误(来自测试):
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");
最佳答案
您的查询应该像
String sql = "SELECT lineText FROM public.dbText_ABCDEF-001 WHERE Textid = ?";
另外,您不能为表名准备语句,因为它仅用于列值