quero um exemplo de como utilizar a classe SimpleDateFormat, para converter a data do banco para o programa (mostrapesquisa())
e um exemplo para converter a data do programa para o banco. (calcular())
não consigo resolver esse problema… aí está a o meu codigo sem o simpledateformat.
espero que alguem possa me ajudar nessa batalha.
os formatos que eu quero utilizar no programa é dd/MM/yyyy
e no banco de dados eu uso o mysql com o formato yyyy-MM-dd
resolvido[code]
private void mostraPesquisa(List cheques) throws ParseException {
while (tmCheque.getRowCount() > 0) {
tmCheque.removeRow(0);
}
if (cheques.size() == 0) {
JOptionPane.showMessageDialog(null, "Nenhum cheque cadastrado");
} else {
String[] linha = new String[]{null, null, null, null, null, null, null};
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");//formato do mySQL
SimpleDateFormat sdf2 = new SimpleDateFormat("dd/MM/yyyy");//formato para mostrar
for (int i = 0; i < cheques.size(); i++) {
Date dataven = sdf1.parse(cheques.get(i).getDataven());
Date datapag = sdf1.parse(cheques.get(i).getDatapag());
tmCheque.addRow(linha);
tmCheque.setValueAt(cheques.get(i).getIdc(), i, 0);
tmCheque.setValueAt(cheques.get(i).getNomecliente(), i, 1);
tmCheque.setValueAt(cheques.get(i).getBanco(), i, 2);
tmCheque.setValueAt(cheques.get(i).getAgencia(), i, 3);
tmCheque.setValueAt(cheques.get(i).getConta(), i, 4);
tmCheque.setValueAt(cheques.get(i).getNumcheque(), i, 5);
tmCheque.setValueAt(cheques.get(i).getValor(), i, 6);
tmCheque.setValueAt(sdf2.format(dataven), i, 7);
tmCheque.setValueAt(sdf2.format(datapag), i, 8);
}
}
}[/code]