inserer un attribut de type Timestamp
Bonjour;
J'ai un java bean qui contient un attribut de type Timestamp :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| import java.sql.Timestamp;
public Class toto {
private Timestamp cdate; //date de création
}
avec les getter/setter :
public Timestamp getCdate() {
return cdate; }
public void setCdate(Timestamp cdate) {
this.cdate = cdate; } |
Lorsque j'insére un objet toto dans la base (MySQL) comment je fait l'insertion ?
Comme ça :
Code:
1 2 3 4 5 6 7 8
| public int insert(Toto t) {
...
stmt = conn.prepareStatement(
"INSERT INTO TOTO (TOTOID, CREATEDATETIME) VALUES (?, ?, )");
stmt.clearParameters();
stmt.setString(1, t.getTotoId());
stmt.setTimestamp(2,new Timesstamp(t.getCdate().getTime()));
stmt.executeUpdate(); |
Merci;