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

Mostrar registros en jsqp

Estas en el tema de Mostrar registros en jsqp en el foro de Java en Foros del Web. Saludos gentita deseo mostrar datos de una tabla productos usando la consulta (SELECT * FROM PRODUCTOS WHERE PREPRO='"+xPre1+"' and PREPRO='" + xPre2+ "') pero me ...
  #1 (permalink)  
Antiguo 05/12/2014, 13:41
Avatar de frankjoel86  
Fecha de Ingreso: noviembre-2008
Ubicación: Ica
Mensajes: 295
Antigüedad: 15 años, 5 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.
  #2 (permalink)  
Antiguo 05/12/2014, 13:54
Avatar de Profesor_Falken  
Fecha de Ingreso: agosto-2014
Ubicación: Mountain View
Mensajes: 1.323
Antigüedad: 9 años, 8 meses
Puntos: 182
Respuesta: Mostrar registros en jsqp

Buenas,

¿Y que error es ese que te sale?
¿Donde inicializas la conexión y el statement?

Un saludo
__________________
If to err is human, then programmers are the most human of us
  #3 (permalink)  
Antiguo 05/12/2014, 23:03
Avatar de frankjoel86  
Fecha de Ingreso: noviembre-2008
Ubicación: Ica
Mensajes: 295
Antigüedad: 15 años, 5 meses
Puntos: 0
Respuesta: Mostrar registros en jsqp

Tengo una clase manejador que contiene el statement e iniciliza la conexión:

package controles;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class claseManejador {
public static Connection cn=null;
Statement st=null;
ResultSet rs=null;
public claseProductos productos=new claseProductos();
public void conectar(String xbase, String xusuario, String xclave){
try {
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
xbase="jdbc:mysql://localhost:3306/"+xbase;
cn=DriverManager.getConnection(xbase,xusuario,xcla ve);
productos.iniciaProductos(cn);

} catch (SQLException ex) {
Logger.getLogger(claseManejador.class.getName()).l og(Level.SEVERE, null, ex);
}
}
}

----------------------------------------------------------------------------
El error que me sale es:
------------------------------------------------------------------------------
HTTP Status 500 - Internal Server Error

type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
root cause

java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1 logs.

GlassFish Server Open Source Edition 4.1


*Gracias por la sugerencia, gracias
__________________
www.basritours.com
Agencia de turismo en Ica.
  #4 (permalink)  
Antiguo 06/12/2014, 02:54
Avatar de Profesor_Falken  
Fecha de Ingreso: agosto-2014
Ubicación: Mountain View
Mensajes: 1.323
Antigüedad: 9 años, 8 meses
Puntos: 182
Respuesta: Mostrar registros en jsqp

Cita:
org.apache.jasper.JasperException: java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
root cause
Y como sabes que el error se está produciendo en la consulta de arriba?

No tienes en el log o en la salida de la consola ninguna pila de llamadas que te indique le linea en la que se produce el error?

Y sobre todo. Si tu aplicación es web... porqué estás utilizando un javax.swing.table.DefaultTableModel???


Un saludo
__________________
If to err is human, then programmers are the most human of us
  #5 (permalink)  
Antiguo 07/12/2014, 07:43
Avatar de frankjoel86  
Fecha de Ingreso: noviembre-2008
Ubicación: Ica
Mensajes: 295
Antigüedad: 15 años, 5 meses
Puntos: 0
Respuesta: Mostrar registros en jsqp

gracias por la atención prestada Profesor_Falken, el error que sale en la pestaña de abajo JAVA DB DATAQBASE PROCESS dice:
---------------------------------------------------------------------------
Sun Dec 07 08:41:36 COT 2014 : Se ha instalado el administrador de seguridad utilizando la directiva de seguridad de servidores básica.
Sun Dec 07 08:41:39 COT 2014 : Apache Derby Network Server - 10.8.2.2 - (1181258) se ha iniciado y está listo para aceptar conexiones en el puerto 1527
__________________
www.basritours.com
Agencia de turismo en Ica.

Etiquetas: clase, jsp, registros, string
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:03.