Problema com preparedstatement

2 respostas
C

Pessoal, eu to sofrendo pra achar um problema aparente inexistente na minha sintaxe sql. Eu estou usando preparedstatement para inserir, alterar… em fim… So que é a segunda vez que eu tenho problema com a sintaxe do update aparentemente estou fazendo tudo certo, mas o jdbc me retorna uma exceção não sei porque!?

Gostaria que vocês me dessem uma ajudinha pra resolver esse problema…

Meu codigo de inserção é esse:

public static void altera(HospEstado he) throws SQLException, ClassNotFoundException {
        //SQL
        PreparedStatement prs = SingleConnect.getConnection().prepareStatement("update hosp_estados set id_quarto=?, set ctrl=?, set toalhas=?, set lencois=?, set redes=? where id=?");

        //Executa SQL
        prs.setInt(1, he.getId_quarto());
        prs.setInt(2, he.getCtrl());
        prs.setInt(3, he.getToalhas());
        prs.setInt(4, he.getLencois());
        prs.setInt(5, he.getRedes());
        prs.setInt(6, he.getId());
        
        prs.execute();
        prs.close();
    }

Eu estou usando o mysql 5 no ubuntu, como o programa esta em fase de testes estou usando o usuario root.

A excessão que eu recebo é essa:
1064-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 ‘set ctrl=1, set toalhas=2, set lencois=2, set redes=0 where id=2’ at line 1

DESDE JÁ AGRADEÇO A FORÇA. VALEU :slight_smile:

2 Respostas

C

CONSEGUI LOCALIZAR O ERRO :roll:

a SINTAXE CORRETA SERIA A SEGUINTE…

PreparedStatement prs = SingleConnect.getConnection().prepareStatement("update hosp_estados set id_quarto=?,  ctrl=?, toalhas=?, lencois=?, redes=? where id=?");
TiD

É isso ai mesmo, o SET da clausula UPDATE só aparece 1 vez a query…

Criado 12 de maio de 2009
Ultima resposta 13 de mai. de 2009
Respostas 2
Participantes 2