I have field in MySQL table which i set it to default value as timestamp,when I update it first time it get update to current timestamp and when I update it second time then also it get update to current timestamp bt when I update the same third time with same value in column timestamp field not get update to current timestamp.
My table structure is:
+-----------+-----------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-----------+------+-----+-------------------+-----------------------------+
| EID | int(11) | NO | PRI | 0 | |
| MOD_EID | int(11) | YES | | NULL | |
| EXIT_TIME | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+-----------+-----------+------+-----+-------------------+-----------------------------+
when I update first time I am inserting required value in EID and 0 in MOD_EID. When I update second time I am updating MOD_EID with required value. In both cases I able to get current_timestamp in EXIT_TIME.
But when I update MOD_EID field again with the same value after minute or one day , EXIT_TIME field not getting update to current_timestamp?
what’s wrong
The code for update is
String vexit=request.getParameter("string");
StringTokenizer tok=new StringTokenizer(vexit,"");
String sql,query,query2;
int count2=0;
while(tok.hasMoreTokens())
{
String ide=tok.nextToken();
sql="SELECT count(EID) FROM tm_exit where EID='"+ide+"' ";
ResultSet rs=st.executeQuery(sql);
while(rs.next())
{
count2=rs.getInt(1);
}
if(count2 >0)
{
query="UPDATE tm_exit set MOD_EID='"+ide+"' WHERE EID='"+ide+"'";
int flag=st.executeUpdate(query);
}
else
{
query2="INSERT INTO tm_exit (EID,MOD_EID)values('"+ide+"',0)";
int flag2=st.executeUpdate(query2);
}
}
A TIMESTAMP column is only updated automatically if the value of some other column changes. If you set MOD_EID to the same value as it already had, the TIMESTAMP won’t be updated. I don’t know why it used to work for you, here’s what the documentation says: