How to correctly set the current time stamp into this Java CRUD method that insert a value into a MySql table? -
i have following table mysql database:
create table log( timestamp timestamp not null, action enum('addperson', 'getperson', 'getpeople', 'updateperson', 'deleteperson', 'deleteall') not null, primary key (timestamp) );
now implementing java insert crud method dao finding problem setting timestamp value (initialized current date time) related prepared statment.
so doing this:
public void addentry(string message) throws sqlexception { // connection object singleton , used connection same crud methods: connection conn = database.getinstance().getconnection(); preparedstatement p = conn.preparestatement("insert log (timestamp, action) values (?,?)"); p.settimestamp(1, new timestamp(time)); }
but gime men error on creation of timestamp object because need long value. think not !!!
how can set current timestamp (the current date-time)?
tnx
try this: p.settimestamp(1, new timestamp(system.currenttimemillis()));
note: i'd recommend check javadoc before posting on so. helps.
Comments
Post a Comment