Pessoal,
boa tarde. eh minha 1 msg e gostaria da ajuda de todos.
bom preciso receber o valor de um textbox e joga-lo pra dentro de uma consulta sql … pesquisei um pouco e estou quebrando cabca com alguns deles. o que preciso é basico … receber um nome e pesquisa-lo num sql .
segue arquivo
<%@include file=“conexao.jsp”%>
<html>
<head>
<title>Consulta por Nome < - Teste JSP - ></title>
</head>
<body>
<h1>Pesquisa por nome </h1>
<%
String sql = "SELECT nome, telefone from aluno LIKE '%" + request.getParameter("nome") + "%' ";
// string que funciona - "Select nome, telefone from aluno WHERE nome = LIKE 'a%' ";
sql = "SELECT * FROM dados WHERE id LIKE '%" + request.getParameter("id") + "%' ORDER BY id";
//String sql = "Select codigo, nome, telefone from aluno WHERE nome LIKE '%"+txt_consulta.getText()+"%' ";
// String sql = "Insert into aluno(nome, telefone) ";
//sql += "values ('" + request.getParameter("nome")+ "','" + request.getParameter("tel")+ "') ";
rs = stm.executeQuery(sql);
// xSQL ="SELECT * FROM DISCO WHERE NM_DISCO LIKE " + "'*" + txtLabel.getText() + "*'";
// Primeiro vamos montar o comando SQL.
// String comando = "SELECT * FROM itens";
// String subq1 = null, subq2 = null, subq3 = null;
// if (usaDescrição.isSelected())
// subq1 = " descricao LIKE '%"+descrição.getText()+"%' ";
// consulta por nome SELECT * FROM teste WHERE nome ILIKE '%texto%'
%>
<a >voltar ao menu </a> <br><br>
<table border=1 width="50%">
<th> NOME </th>
<th> TELEFONE </th>
<th width="10%" colspan=2 align="center" bgcolor="#cccccc"> OPÇÕES </th>
<%
try
{
while(rs.next())
{
%>
<form name="frm" action="index.jsp">
<tr>
<input type="hidden" name="codigo" value="<%=rs.getString("codigo")%>">
<td nowrap> <%=rs.getString("nome")%> </td>
<td nowrap> <%=rs.getString("telefone")%> </td>
<td nowrap> <input type="submit" name="opcao" value="alterar"> </td>
<td nowrap> <input type="submit" name="opcao" value="excluir"> </td>
<p> teste pegar valor = String coluna1 = rs.getString("nome") <br>
<p> teste -- !! <td nowrap> <%=rs.getString("nome")%> </td> <br>
</tr>
</form>
<%
}
} catch (Exception e) {
out.println("Houve erro ao tentar se conectar... ");
}
finally {
try {
stm.close();
con.close();
} catch (Exception e) {}
}
%>
</table>
entre com o nome a ser pesquisado: <input name="txt_consulta" type="text" id="txt_consulta"> <input type="submit" name="Submit" value="consultar">
<form name=“frm_envia_consulta” method=“post” action="">
</form>