I have an app to develop where it contains many tables of database, I gone through some of the tutorials online, and I want to ask if I have many tables that are not connected to each other (just for storing and displaying purposes, no manipulation etc), are each of the tables must have their own Java class?
2 Answers
If you want to have an ORM (for a concrete example please take a look here) and if these tables have nothing in common with each other, then yes, it's better to have distinct class for every table. But if you are not aimed to use ORM, then you don't need even classes, you are free to use data you get from DB on your own. Also please note, that you should have one class for serving DB requests. If you are using SQLite, it may be the class extending SQLiteOpenHelper and it's better to build it as singletone.
3 Comments
One class for database (and in fact, for application) is enough. There is no need for maintaining each table in separate class. It is really easier to maintain all tables in one class. Additionally, if you'd like to create join of two tables, it would be really tough thing to do using multiple classes. With one class it can be done internally there.
Of course, if you would have to maintain many classes (20 for example) it would be a good idea to group them depends on what the store. But one class per table is really not necessary