Senhores,
Estou utilizando preparedstatament em minha aplicação abrindo um arquivo Properties, sempre que executo a aplicação recebo o erro abaixo:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1564)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1485)
at br.com.systemcli.db.UsuarioDB.salvarUsuario(UsuarioDB.java:40)
… 1 more
Java Result: 1
public void alterarUsuario (Usuario usuario) throws SystemcliException {
PreparedStatement stmt = null;
AbreConsulta abs = new AbreConsulta ();
Properties retorno = abs.AbreConsultaSQL("ArquivoSQL.properties");
String sql = retorno.getProperty("usuario.alterar");
Connection conn = ConnectionManager.getConexao();
try {
stmt = conn.prepareStatement(sql);
stmt.setString(1, usuario.getNome());
stmt.executeUpdate();
}catch (SQLException e){
throw new SystemcliException ("Erro ao alterar usuário", e);
}finally {
ConnectionManager.close(conn, stmt);
}
}
O mais interessante é que quando não coloco a ? (interrogação), o sistema funciona normalmente.
Query: insert into teste (nome) values (?)
Alguém sabe me dizer o que é?
Obrigado pela atenção