SQL Syntax error in PreparedStatement appearing only with setObject Integer
using:
-MySQL 4.1.12
-mysql-connector-java-3.1.10
Hello,
it is only a example for one value from Map. For String it works good.
Problem arisses with setting Int value from Map. When I replace '?'
with the number (for example 1) and put it into my MySQL Command Centrer
command line - it is correct SQL query, which returns
right result.
I get this error:
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?) ORDER BY flotila.nazev ASC' at line 1
executing this code:
Map where =new HashMap ();
where.put ("imperium.id_imperium",new Integer( 1 ));
String whole_query =" SELECT * FROM flotila, imperium WHERE (imperium.id_imperium = flotila.id_imperium) AND (imperium.id_imperium = ?) ORDER BY flotila.nazev ASC";
PreparedStatement pstmt = conn.prepareStatement(whole_query);
for (Iterator i = where.values().iterator(); i.hasNext(); ){
Object o = i.next();
pstmt.setObject (1,o);
ResultSet rs = pstmt.executeQuery(whole_query);

