Bom dia Galera, estou criando um site em HTML/JSP com banco de dados MYSQL, gostaria de fazer uma consulta pela combox e uma textfild mas estou com dificuldade, alguém poderia me da uma dica como fazer essa consulta?
Obs: Com a textfield eu consigo fazer a consulta normal, o difícel é fazer a busca com os dois campo.
Valeu Galera…
O que você quer dizer com consulta? e aonde entra o JavaScript nessa história ?
Quero fazer a consulta pela combobox e pelo txtnome, só consigo fazer pelo txtnome até o momento.
Obrigado pelo resposta.
<html>
<head>
<title> </title>
</head>
<body>
<h1 align=“center”>Consulta de Usuários</h1>
<form name=“Formulario” action=“Consulta_Por_Nome.jsp” method=“post”>
<table border="1" align="center">
<tr>
<td>Pesquisar Por:</td>
<td><select name=“cmbprocurar” id=“cmbprocurar”>
<option value=“codigo”>Código</option>
<option value=“nome”>Nome</option>
<option value=“cpf”>CPF</option></td>
<td><input type=“text” name=“txtnome” size=“50”></td>
<td><input type=“submit” value=“Buscar” ></td>
</tr>
</table>
</form>
<%@ page language=“java” import=“java.sql.*” %>
<%
String driver= “com.mysql.jdbc.Driver” ;
String url = “jdbc:mysql://localhost:3306/Projeto” ;
String user = “root” ;
String pass = “root” ;
String vnome = request.getParameter(“txtnome”) ;
String procurar = request.getParameter(“cmbprocurar”);
String sql ;
if ( vnome == “” ) {
sql=“select * from usuarios”;
}else{
sql = “select * from Usuarios where '”+ procurar + “’ like '” + vnome + “’”;
}
Class.forName(driver);
Connection conexao = DriverManager.getConnection(url,user,pass);
Statement stm = conexao.createStatement();
ResultSet resultado = stm.executeQuery(sql) ;
out.print( “<table border=1>” ) ;
while ( resultado.next() ) {
out.print( “<tr>” ) ;
out.print( “<td>” ) ;
out.print( resultado.getString(“codigo”) ) ;
out.print( “</td>” ) ;
out.print( “<td>” ) ;
out.print( resultado.getString(“nome”) ) ;
out.print( “</td>” ) ;
out.print( “<td>” ) ;
out.print( resultado.getString(“email”) ) ;
out.print( “</td>” ) ;
out.print( “</tr>” ) ;
}
%>
</body>
</html>