Foros del Web » Programación para mayores de 30 ;) » Java »

buscar en mysql por javaweb

Estas en el tema de buscar en mysql por javaweb en el foro de Java en Foros del Web. hgola a todos..lo que pasa es que intento buscar a partir de un campo de texto en una pagina jsp que vaya hacia un servlet ...
  #1 (permalink)  
Antiguo 04/10/2011, 15:42
Avatar de gianfranc  
Fecha de Ingreso: octubre-2011
Ubicación: san isidro-peru
Mensajes: 21
Antigüedad: 12 años, 7 meses
Puntos: 0
buscar en mysql por javaweb

hgola a todos..lo que pasa es que intento buscar a partir de un campo de texto en una pagina jsp que vaya hacia un servlet que se llama ProductosServlet este es el codigo:

<form action="ProductosServlet" method="post">

<div align="center" class="ui-widget">
<label ">Buscar producto: </label>
<input type="text" name="txtbuscar "id="txtbuscar" value="" />

<input type="submit" name="buscar" value="buscar" ><BR>

</div>
</form>


<table align="center" width="70%" border="1" >
<tr>
<th>Código</th>
<th>Nombre</th>
<th>Precio</th>
<th>Stock</th>
<th>Proveedor</th>
<th>Categoria</th>
</tr>
<%
List<ProductosBean> lista = (List<ProductosBean>)request.getAttribute("listarP roducto");



for(int i=0; i<lista.size(); i++)
{
%>
<tr>
<td><%= lista.get(i).getCodigo() %></td>
<td><%= lista.get(i).getNombre() %></td>
<td><%= lista.get(i).getPrecio() %></td>
<td><%= lista.get(i).getStock() %></td>
<td><%= lista.get(i).getProveedor() %></td>
<td><%= lista.get(i).getCategoria() %></td>


<% } %>
</table>



ESTE ES EL CODIGO EN EL SERVLET:

if(request.getParameter("accion").equals("buscar") )
{
try {
// Recupera variable codigo

String pro=request.getParameter("producto");
// Llamo a DAO - Bean lleno
ProductosBean producto = new ProductosService().BuscarProductos(pro);
// Pasar bean (ámbito: request)
request.setAttribute("producto", producto);
// Llamo a la página


} catch (Exception ex) {
ex.printStackTrace();
muestraLista(request, response);
}
}

EL PRODUCTO SERVICE SE CONECTA CON EL PRODUCTOSDAO QUE ES EL SGT:

public ProductosBean BuscarProducto(String producto)
throws Exception{

ProductosBean productoobt = null;
Connection cn = new ConectaDB().getConexion();
Statement st = cn.createStatement();
ResultSet rs = st.executeQuery("select * from productos where nombre like '%"+producto+"%'");
if (rs.next())
{
productoobt = new ProductosBean(rs.getInt("codigo"),rs.getString("no mbre"), rs.getDouble("precio"),rs.getInt("stock"),rs.getSt ring("proovedor"),rs.getString("categoria"));
}
cn.close();
return productoobt;

ESTA ES LA IMAGeN QUISIERA QUE CUANDO BUSKE LO ENCUENTRE EN LA TABLA Y SALGA LA FILA CON EL RESULTADO:

TODA AYUDA SERA BIENVENIDA Y AGRADECIDA...




http://www.imagengratis.org/?v=tablanm1sn.jpg

Etiquetas: jsp, mysql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:52.