Erro de Sintax SQL

4 respostas
TheKill

String op= (String) Lista.getSelectedItem(); ResultSet rs = st.executeQuery("select * from Veiculo where Modelo '=" + op + "and where Locado is Null order by Modelo");

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 ''=nulland where Locado is Null order by Modelo' at line 1

Pessoal pesso ajuda ai, Obrigado pela atençao

Att. Jonas Teixeira de Freitas.

4 Respostas

_fs

Falta um espaço depois de “op”.

O certo ficaria:

ResultSet rs = st.executeQuery("select * from Veiculo where Modelo '=" + op + " and where Locado is Null order by Modelo");

Mas o certo MESMO seria usar PreparedStatements:

TheKill

[quote=LIPE]Falta um espaço depois de “op”.

O certo ficaria:

ResultSet rs = st.executeQuery("select * from Veiculo where Modelo '=" + op + " and where Locado is Null order by Modelo");

Mas o certo MESMO seria usar PreparedStatements:

Amigo testei seu Code mas tbm nao funcionou, gerou o seguinte erro.

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 ''=null and where Locado is Null order by Modelo' at line 1
Obrigado, aguardo resposta

TheKill

PreparedStatement pstmt = con.prepareStatement("select * from Veiculo where Modelo = ? and where Locado is Null order by Modelo"); pstmt.setString( 1, op ); ResultSet rs = pstmt.executeQuery();

Tentei esse codigo tbm, mas tbm gerou erro de Sintaxe.
Peço Ajuda é importante preciso terminar esse projeto.

Att. Jonas Teixeira de Freitas

dreamspeaker

não tem o segundo “where”

Criado 21 de junho de 2007
Ultima resposta 21 de jun. de 2007
Respostas 4
Participantes 3