Help to fill jTable

2

I'm filling a jtable with the birthdays that are registered in a database.

  public void jTablePop()
{
    javax.swing.table.DefaultTableModel dtm2 = (javax.swing.table.DefaultTableModel)jTable1.getModel();  
    dtm2.setNumRows(0);  
    //ISSO TIRA AS LINHAS DA TABELA  
    int x=0;

    try{
    conexao.Conectar();

    conexao.sql = "select cli_nome,cli_cpf,cli_data_nascimento from contrato where  id_cli > 1 ";
    conexao.ps = conexao.con.prepareStatement(conexao.sql);
    conexao.rs = conexao.ps.executeQuery();

    while(conexao.rs.next())
    {
        //codigo
        dtm2.addRow(new Object[]{" ","  "," "}); 
        jTable1.setValueAt(conexao.rs.getString(1),x,0);  
        jTable1.setValueAt(conexao.rs.getString(2),x,1);  
        jTable1.setValueAt(conexao.rs.getString(3),x,2); 
        x++;
    }


    }catch(SQLException ex){
           JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "ERRO!", JOptionPane.ERROR_MESSAGE);
       }
}

But I need jTable to appear only the birthdays of the month, how could I do this? I have already put the date in a variable like this:

public void kappa()
    {
        SimpleDateFormat sdf1= new SimpleDateFormat("dd/MM/yyyy"); 
        Date y=new Date(); 
        String keppo = sdf1.format(y).toString();

    }

How could I display jTable just the birthdays of the month? could you help me?

    
asked by anonymous 14.10.2015 / 18:03

1 answer

0

I was able to do this, if anyone reading this had the same doubt. Here's the solution:

 public void jTablePop()
    {

        javax.swing.table.DefaultTableModel dtm2 = (javax.swing.table.DefaultTableModel)jTable1.getModel();  
        dtm2.setNumRows(0);  

        int x=0;

        try{

        conexao.Conectar();
        Calendar c1= Calendar.getInstance();
        String hora1 = c1.get(Calendar.DAY_OF_MONTH)+"/"+(c1.get(Calendar.MONTH)+1);
        se.setText(hora1);

        conexao.sql = "SELECT cli_nome,tel,cli_data_nascimento FROM contrato WHERE LEFT(cli_data_nascimento,5) =?";
        conexao.ps = conexao.con.prepareStatement(conexao.sql);
        conexao.ps.setString(1,se.getText());
        conexao.rs = conexao.ps.executeQuery();

        while(conexao.rs.next())
        {
            //codigo
            dtm2.addRow(new Object[]{" ","  "," "}); 
            jTable1.setValueAt(conexao.rs.getString(1),x,0);  
            jTable1.setValueAt(conexao.rs.getString(2),x,1);  
            jTable1.setValueAt(conexao.rs.getString(3),x,2); 
            x++;
        }

        }catch(SQLException ex){
               JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "ERRO!", JOptionPane.ERROR_MESSAGE);
           }
    }
    
16.10.2015 / 00:54