got a problem with a preparedstatement using Java 1.7.0.67 on Windows 8.1…
Basically I get an error as follows (from the test):
JavaScript
x
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.
I can see it’s telling me I have no ? but they are there for all to see in the before setString message.
Can anyone see what is wrong with what I’m doing – I’m new to PreparedStatements and I think it’s right…
thanks and regards Seán
JavaScript
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");
Advertisement
Answer
Your query should be like
JavaScript
String sql = "SELECT lineText FROM public.dbText_ABCDEF-001 WHERE Textid = ?";
Also you cannot have prepared statement for table names as it is only for column values