Qual é o sentido do termo LIKE no MySql?
Qual é o sentido do termo LIKE no MySql
G
5 Respostas
Comparar termos não numéricos. Traduzindo literalmente seria : como/parece.
– Select * from tabela where campo like ‘texto’
– Selecione * da tabela onde campo parece ‘texto’
Até!
na pratica seria isso aqui assim oh:
PreparedStatement stmt = this.connection.prepareStatement
("select * from contatos WHERE nome like '%"+nome+"%' order by id");
ResultSet rs = stmt.executeQuery();
S
só pra acrescentar…
- select * from teste where nome = ‘%’
- select * from teste where nome like ‘%’
no primeiro, o mysql vai retornar somente os registros com o campo nome igual a %, já no segundo, ele vai retornar qualquer coisa, assumindo que ‘%’ é um caractere coringa!
T
na pratica seria isso aqui assim oh:PreparedStatement stmt = this.connection.prepareStatement ("select * from contatos WHERE nome like '%"+nome+"%' order by id"); ResultSet rs = stmt.executeQuery();
PreparedStatement não tem "suporte" ao LIKE teria que fazer assim:
E não tem sentido usar PreparedStatement com SQLInjection
PreparedStatement stmt = this.connection.prepareStatement
("select * from contatos WHERE nome like ? order by id");
stmt.setString(1 , nome + "%%");
ResultSet rs = stmt.executeQuery();
Criado 2 de fevereiro de 2007
Ultima resposta 2 de fev. de 2007
Respostas 5
Participantes 6