B4J Question Delete value in database in 24 hours

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

Hoping someone can suggest a way in doing the following..

What I am trying to do is, I am inserting a value into a MySQL database, but I want to delete the value I inserted in 24 hours.

What would be the best way in deleting the value 24 hours after it has been added in the MySQL database ?

I also want to make it so if I re-start the B4J app it will still delete the value in 24 hours when the B4J is running again. (so if I add the value in the database, wait 5 hours, and then kill the B4J app and start it again a minute or so later then it will still delete the value in 19 hours, providing the B4J is running.)

I am wanting to do this in a non-UI app.

The only way I thought of doing this was:
- In the MySQL database add a column for a timestamp and value.
- When I insert the value into the database, then also add it to the map in B4J.
- When the app is opened, connect to the database and load the timestamp and value into a map in the B4J app.
- Run a timer every 30 seconds which will check the map timestamp, and if the timestamp is more then 24 hours since it was created then delete the value out of the database (and delete it from the map).

Is there any better ways in doing this, or is the above the best way in doing this ?
 

DonManfred

Expert
Licensed User
Longtime User
add a timestamp to the data and delete all entries with a Timestamp older than 24h in the past.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
You can add an EVENT in MySQL server database to execute certain command for a schedule time. You do not need to do anything with B4J server.
 
Upvote 0

jerry07

Member
Licensed User
Longtime User
Not directly related to your question but I very rarely delete rows. Most of the time I deactivate row using indicator column and/or timestamp column.
This allows for tracing issues and audit tracking. Just an idea.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Not directly related to your question but I very rarely delete rows. Most of the time I deactivate row using indicator column and/or timestamp column.
This allows for tracing issues and audit tracking. Just an idea.
There are different use cases. Sometimes it is safe to delete a row if the record is not critical or transaction type records.
I also agree with you that I also seldom delete records. That’s why I update the value as Null in my example above.
 
Upvote 0
Top