The Power of a simple SET…

Recently, I installed a new local MySQL Server with the purpose to log debug messages.

But because I had to log a lot of messages disk space became an issue. So I decided to create an event to clear these messages hourly. 

I spent a lot of time trying to understand why the code worked fine in a single execution, but when the same code was inside the event it was not working when the schedule was met. 

After some reasearch I found out that by default event_scheduler global variable is OFF. 

After enabling it, the event started to work.

You just need to execute the line:

SET GLOBAL event_scheduler = ON;



Java – MYSQL – Prepared Statements – Insert Batch

//create prepared statement, bind it to db connection and SQL query.
PreparedStatement = dbConnection.prepareStatement(insertTableSQL);
//For each input value set input type, input position and value.
preparedStatement.set<inputType>(<index>, <value>);
preparedStatement.set<inputType>(<index>, <value>);

//For each new row to be inserted add it to batch 
//After adding to batch all rows to be inserted. 
//It's time to call execute batch.

For a complete example please see source.