We need a java code which can insert the row in a table, if table not exist, then it will create a new and then insert into that table.
Like we are tracking the each request to our server, and then save the same in a table. The table name should be like request_month-name_*year*, which is passed dynamically. The purpose is to keep the table of each month independent of others.
The code which we are using is
try{
dao.insertTracking(object, year, month);
}catch(BadSqlGrammarException e){
dao.createTable(year, month);
dao.insertracking(object, year, month);
}catch(Exception e){
e.printStackTrace();
}
The issue is that the the BadSqlGrammarException can be thrown in many other cases as well.
So my question is to how to handle this type of situation efficiently without catching generalized exception and then processing again?
Also, We can first check the existence of table, but that would put heavy load on system, since large volume of request are handled each day.
Using jdbctemplates and/with mysql.