I’m programming a simple app in java se with jdk 1.7, using netbeans 7.1.2 and MySQL 5.
But i have an error in the next code:
String sql = "SELECT idpaciente, ap_paterno, ap_materno, nombres, edad, direccion, telefono, descuento, movil, email, docId FROM paciente WHERE ap_paterno LIKE ? ";
pst = con.prepareStatement(sql);
pst.setString(1, paciente.getApellidoPaterno());
ResultSet rs = pst.executeQuery(sql);
This code compiling good, but after execute,i have an error of syntax, netbeans says:
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 ‘?’ at line 1
Using debugger of netbeans, the error is in executeQuery, but i can not find my error.
PreparedStatement.executeQuery()does not take any argument, however since the interface inheritsStatement.executeQuery(String sql)you are calling that instead. Just call: