In my application, I want use two different DBHelper classes for working on two different tables.
Is it possible to have more than one DBhelper classes in my app?
Asked
Active
Viewed 124 times
0

Phantômaxx
- 37,901
- 21
- 84
- 115

hemanth5636
- 89
- 2
- 9
-
1Have you tried it? What happened? – nhouser9 Aug 09 '16 at 19:09
-
1You cannot have two classes named `DBHelper` in the same Java package, though you can have them in separate packages. You should not have more than one `SQLiteOpenHelper` per database, if your proposed `DBHelper` is a subclass of `SQLiteOpenHelper`. – CommonsWare Aug 09 '16 at 19:11
-
I experienced that you should only have one dbhelper per database. So for you, with 2 tables in one db , no, i wouldnt recommend to have more than once. I tried it once with more than one and it gave me more disadvantages to handle all the interactions than with one. To be clear: It is possible for sure, but i don't recommend – Henning Luther Aug 09 '16 at 19:13
-
You simply **don't need** to have a distinct class for each table. – Phantômaxx Aug 09 '16 at 19:23
-
i tried it, but table not found exceptions are raised. only one table is creating, so the exception is raised for the other table @nhouser9 – hemanth5636 Aug 09 '16 at 19:43
-
thank you @CommonsWare. you cleared my doubts by " You should not have more than one SQLiteOpenHelper per database, if your proposed DBHelper is a subclass of SQLiteOpenHelper". im not using two classes with same names. thank you so much. – hemanth5636 Aug 09 '16 at 19:47
-
You need to use proper versioning: [When is SQLiteOpenHelper onCreate() / onUpgrade() run?](http://stackoverflow.com/questions/21881992/when-is-sqliteopenhelper-oncreate-onupgrade-run) – CL. Aug 09 '16 at 20:25