First of all,not a good database design and I would recommend you to revisit it.
A bit tricky I would say and would also would depend on what are you using to database like
JDBC or O/R mapping such as Hibernate.
Assuming you are using Hibernate.. every time you change the DB , you will have to regenerate the POJO classes and that would necessarily mean rebuilding and redeploying of the application.
In such a scenario, every time you change the DB you have to manually read the column count and store as a CONSTANT in the application. You can then read this variable and then get the number of columns to generate the table.