Use placeholder in place of table name and then replacing that with your tablename.
String strQuery = "INSERT INTO $tableName (col1, col2)
VALUES (?,?);";
and replace when you come to know the tablename as below:
String query =strQuery.replace("$tableName",tableName);
stmt =connection.prepareStatement(query);