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

Consulta Jtable

Estas en el tema de Consulta Jtable en el foro de Java en Foros del Web. hola amigo del foro tengo una inquiectud tengo un formulario con JTable y JTextField y necesito realizar una consulta que me muetre la informacion en ...
  #1 (permalink)  
Antiguo 03/12/2010, 16:21
 
Fecha de Ingreso: diciembre-2009
Mensajes: 137
Antigüedad: 14 años, 4 meses
Puntos: 4
Consulta Jtable

hola amigo del foro tengo una inquiectud tengo un formulario con JTable y JTextField y necesito realizar una consulta que me muetre la informacion en el Jtable pero no se como hacer. yo quiero q cuando uno se ubiq en el Jtextfield y cuando vaya presionando cada letra me vaya haciendo la consulta.

este es la sentencia mysql
Código:
SELECT * FROM RSBDUAOK WHERE APE1 LIKE '% + JTxtField.getText() +%'
Código PHP:
import java.sql.*;
import BEANS.Conexion;
import CONTROLADORES.AfiliadoControlador;
import java.util.Iterator;
import javax.swing.event.InternalFrameEvent;
import BEANS.Afiliado;

//
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.awt.Rectangle;
import javax.swing.border.EtchedBorder;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

public class 
FrmConsultaAvanzada extends javax.swing.JInternalFrame {
 
Conexion con = new Conexion();
  private 
Afiliado cliente;
  
//consulta
  
Vector datos null;
  
java.util.List list = null;
  
DefaultTableModel dtm;



    public 
FrmConsultaAvanzada() {
        
initComponents();
        
CargarDatos();
       
    }

    
/** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    
public void CargarDatos()
    {

 
javax.swing.table.DefaultTableModel dtm =(javax.swing.table.DefaultTableModel)tablaconsulta.getModel();
        try
        {
            
java.util.List lista cc.findAll();
            
int filas=dtm.getRowCount();
            for(
int i=0;i<filas;i++)
            {
                
dtm.removeRow(0);
            }
            
Iterator it=lista.iterator();
            while(
it.hasNext())
            {
                
Afiliado cliente = (Afiliado)it.next();
                
dtm.addRow(new Object[]{cliente.getCODENTIDAD(),cliente.getTIPAFILIADO(),cliente.getNUMAFILIADO(),cliente.getAPELLIDO1(),cliente.getAPELLIDO2(),cliente.getNOMBRE1(),cliente.getNOMBRE2(),cliente.getFECHANAC(),cliente.getSEXOAFI(),cliente.getCODDPTO(),cliente.getCODMUNAFI(),cliente.getZONAFI(),cliente.getFAFIENTIDAD(),cliente.getTIPPOBLACION(),cliente.getNIVSISBEN(),cliente.getMODASUBSIDIO()});
            }
           
        }
        catch(
Exception exc)
        {
           
System.err.println(exc.getMessage());
         }
    }
                           

    private 
void txtApe1KeyReleased(java.awt.event.KeyEvent evt) {                                    
        
// TODO add your handling code here:
         
txtApe1.setText(txtApe1.getText());
        
    }                                   

    
//
     
public void limpiaryllenar(){
    while(
dtm.getRowCount()>0)
        
dtm.removeRow(0);
      for (
int i 0< list.size(); i++) {
          
dtm.addRow((Vector)list.get(i));
      }
  }
     
//
 
  
static Connection conn;
  private 
AfiliadoControlador cc = new AfiliadoControlador();

    
// Variables declaration - do not modify                     
    
private javax.swing.JLabel jLabel1;
    private 
javax.swing.JLabel jLabel2;
    private 
javax.swing.JLabel jLabel3;
    private 
javax.swing.JLabel jLabel4;
    private 
javax.swing.JLabel jLabel5;
    private 
javax.swing.JScrollPane jScrollPane1;
    private 
javax.swing.JTable tablaconsulta;
    private 
javax.swing.JTextField txtApe1;
    private 
javax.swing.JTextField txtApe2;
    private 
javax.swing.JTextField txtDocumento;
    private 
javax.swing.JTextField txtNom1;
    private 
javax.swing.JTextField txtNom2;
    
// End of variables declaration                   


este es la clase de conexion

Código PHP:
package BEANS;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.sql.*;
/**
 *
 * @author Admon
 */
public class Conexion {

    
//transient java.sql.Connection con;
       
Connection con null;
    private 
String jdbcDriver="com.mysql.jdbc.Driver";
    private 
String databaseUrl="jdbc:mysql://localhost:3306/RSLAPAZ";

    public 
String getJdbcDriver()
    {
        return 
this.jdbcDriver;
    }
    public 
String setJdbcDriver(String JdbcDriver1)
    {
        return 
this.jdbcDriver=JdbcDriver1;
    }
    public 
String getDatabaseUrl()
    {
         return 
this.databaseUrl;
    }
     public 
void setDatabaseUrl(String DataBaseUrl1)
    {
      
this.databaseUrlDataBaseUrl1;
    }
     public 
boolean isConecction()
     {
         if(
this.con==null)
         {
             return 
false;
         }else{
         return 
true;
         }
     }
     public 
void conectar(String usuString pasthrows java.sql.SQLExceptionIOException
     
{
         
Properties pro = new Properties();
         
InputStream is=null;
         
String equipo="";
         
String usuario="";
         
String password="";
         try
         {
             
is=new FileInputStream("configuracion.properties");
             
pro.load(is);
             
equipo=pro.getProperty("equipo");
             
usuario=pro.getProperty("user");
             
password=pro.getProperty("password");
             

         }catch(
Exception e)
         {
            throw new 
SQLException("No hay Datos de Configuracion Para la conexion a la BD, No se encuentra el archivo configuracion.properties");
         }
         if(
isConecction())
             throw new 
java.sql.SQLException("ESTA CARGADA LA BD");
         if(
this.jdbcDriver==null)
             throw new 
java.sql.SQLException("NO SE ENCUENTRA EL JDBC DRIVER CARGADO");
         if(
this.databaseUrl==null)
             throw new 
java.sql.SQLException("NO SE ENCUENTRA URL EN LA BD CARGADA");
         try
         {
             Class.
forName(this.jdbcDriver).newInstance();
         }
         catch(
Exception e)
         {
             throw new 
java.sql.SQLException("NO SE PUEDE CARGAR EL JDBC DRIVER" +this.jdbcDriver);
         }
         
con=java.sql.DriverManager.getConnection("jdbc:mysql://"+equipo+":3306/RSLAPAZ",usuario,password);

     }
 public 
void conectar()
     {
         
Properties pro = new Properties();
         
InputStream is=null;
         
String equipo="";
         
String usuario="";
         
String password="";
         try
         {
             
is=new FileInputStream("configuracion.properties");
             
pro.load(is);
             
equipo=pro.getProperty("equipo");
             
usuario=pro.getProperty("user");
             
password=pro.getProperty("password");


         }catch(
Exception e)
         {
            
System.out.println("No hay Datos de Configuracion Para la conexion a la BD, No se encuentra el archivo configuracion.properties");
         }
         if(
isConecction())
             
System.out.println("ESTA CARGADA LA BD");
         if(
this.jdbcDriver==null)
             
System.out.println("NO SE ENCUENTRA EL JDBC DRIVER CARGADO");
         if(
this.databaseUrl==null)
             
System.out.println("NO SE ENCUENTRA URL EN LA BD CARGADA");
         try
         {
             Class.
forName(this.jdbcDriver).newInstance();
         }
         catch(
Exception e)
         {
             
System.out.println("NO SE PUEDE CARGAR EL JDBC DRIVER" +this.jdbcDriver);
         }
        try
        {
            
con=DriverManager.getConnection("jdbc:mysql://"+equipo+":3306/RSLAPAZ",usuario,password);
        }catch(
Exception e)
        {
            
e.printStackTrace();
        }

     }
       
    public 
java.sql.Connection getConection()
       {
           return 
this.con;
       }
       public 
void desconectar()
       {
           if(
this.con!=null)
           {
               try
               {
                   
this.con.close();
               }catch(
java.sql.SQLException e)
               {}
finally{
                   
this.con=null;
               }

           }
       }
public 
Connection getConnection(){
      return 
con;
   } 

Etiquetas: jtable
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 17:59.