1
I would like to add 45 days on my date2, from the date1 Example:
data2 = data1+45
public void adiciona(Usuario usuario){
String sql = "INSERT INTO usuario(nome,endereco,cpf,email,telefone,data1,data2) VALUES(?,?,?,?,?,?,?)";
try {
PreparedStatement stmt = connection.prepareStatement(sql);
java.sql.Date data1 = new java.sql.Date(usuario.getData1().getTime());
stmt.setString(1, usuario.getNome());
stmt.setString(2, usuario.getEndereco());
stmt.setString(3, usuario.getCpf());
stmt.setString(4, usuario.getEmail());
stmt.setString(5, usuario.getTelefone());
stmt.setDate(6, data1);
stmt.setDate(7, data2 ); //QUERO ADICIONAR A DATA2 NO BANCO COM 45 DIAS APÓS A DATA1, COMO FAZER?
stmt.execute();
stmt.close();
} catch (SQLException u) {
throw new RuntimeException(u);
}
}
interface
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// instanciando a classe Usuario do pacote modelo e criando seu objeto usuarios
Usuario usuarios = new Usuario();
usuarios.setNome(jTextField1.getText());
usuarios.setEndereco(jTextField2.getText());
usuarios.setCpf(jTextField3.getText());
usuarios.setEmail(jTextField4.getText());
usuarios.setTelefone(jTextField5.getText());
usuarios.setData1(jDateChooser1.getDate());
Partner, thank you so much for the help. I solved my problem. Now next.. My system needs to send emails 2 days before each date. How do you advise me to do this? Would it be the case every time the system calls it check for emails to be sent? If you can give a light, it would be great!! Thank you dnv for the help!
– user11464
@user11464 although this is a completely new issue and you can create a new topic for it, I’ll say what I think here because I won’t go on long. It depends a little on how your system works, if you turn on the system every day you can check yes the way you said, if it stays on all the time you should include some timer or set some event that will trigger the verification of the need of sending the email. If my comment left you with questions create a new question, and do not forget to give plenty of details, including whether it is a web system, desktop or Android.
– Math