2
I’m filling out a jtable with the birthday kids who 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 that in jTable appear only the birthday of the month, how could I do it ? I’ve managed to date a variable this way :
public void kappa()
{
SimpleDateFormat sdf1= new SimpleDateFormat("dd/MM/yyyy");
Date y=new Date();
String keppo = sdf1.format(y).toString();
}
How could I do to display on jTable only the birthday of the month ? could help me ?
First take the current month using the Calendar library, then you convert your birth date into Calendar and take only the month as well. Finally makes an if inside that while checking whether the months are equal.
– DiegoAugusto