Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/12/2014, 13:41
Avatar de frankjoel86
frankjoel86
 
Fecha de Ingreso: noviembre-2008
Ubicación: Ica
Mensajes: 295
Antigüedad: 16 años, 4 meses
Puntos: 0
Mostrar registros en jsqp

Saludos gentita deseo mostrar datos de una tabla productos usando la consulta (SELECT * FROM PRODUCTOS WHERE PREPRO='"+xPre1+"' and PREPRO='" + xPre2+ "')

pero me sale error. dejo el código:
------------------------------------- CLASEPRODUCTOS-----------
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

public class claseProductos {
static Connection xcn=null;
Statement xst=null;
ResultSet xrs=null;
DefaultTableModel xdatos=new DefaultTableModel();



public DefaultTableModel buscaProductos(String xPre1, String xPre2){
try {
String sqlBusca="select * from productos where PREPRO='"+xPre1+"' and PREPRO='" + xPre2+ "'";
xrs=xst.executeQuery(sqlBusca);
while(xrs.next()){
String fila[]={xrs.getString(1),xrs.getString(2),xrs.getString( 3)};
xdatos.addRow(fila);
}
return xdatos;
} catch (SQLException ex) {
Logger.getLogger(claseProductos.class.getName()).l og(Level.SEVERE, null, ex);
}
return xdatos;
}

}

---------------------PAGINAPRODUCDOS.JSP---------------------
<%@page import="controles.claseManejador"%>
<%@page import="javax.swing.table.DefaultTableModel" %>
<%@page session="true" %>


<%
String xcod="",xnom="",xrec="",xpre="";
String xcodtu="",xnomtu="",xdoctu="",xprotu="";
String xnropaq="",xsalida="",xhora="";
String nrobol="", xPre1="", xPre2="";

String xpre1, xpre2;

DefaultTableModel datos = new DefaultTableModel();
claseManejador myDB=new claseManejador();
myDB.conectar("turismo", "root", "");

//lectura de la sesion
HttpSession sessionBol=request.getSession();

if(request.getParameter("ok")!=null){
xpre1=request.getParameter("txtPre1");
xpre2=request.getParameter("txtPre2");
myDB.productos.buscaProductos(xpre1, xpre2);

xcod=datos.getValueAt(0, 0).toString();
xnom=datos.getValueAt(0,1).toString();
xrec=datos.getValueAt(0,2).toString();
}
%>

<form name="form1" action="index.jsp" method="POST">
<table border="1">
<thead>
<tr>
<th>Precio 1 <input type="text" name="txtPre1" value="" /></th>
<th>Precio 2 <input type="text" name="txtPre2" value="" /></th>
<th><input type="submit" value="Buscar" name="ok" /></th>
</tr>
</thead>
<tbody>
<tr align="center">
<td>Codigo</td>
<td>Producto</td>
<td>Precio</td>
</tr>

<tr>
<td><%= xcod %></td>
<td><%= xnom %></td>
<td><%= xrec %></td>
<td><%= xpre %></td>

</tr>
</table>

gracias de antemano por la sugerencias. (Y)
__________________
www.basritours.com
Agencia de turismo en Ica.