0

Is there a way to generate SqliteHelpers classes from SQL script without creating theme manualy ? in other words i have a database with 20 tables that i need to use in an android application with Sqlite database and don't want to create manualy SqliteHelper classe for every table.

4
  • Welcome to SO. It will help if you post: What have you tried so far? Do you have any starting code you are stuck with? Commented Jan 10, 2015 at 20:08
  • Thank you ! I just start with android developement and i don't know if there is a way to generate SqlHelper's Classes from sql script. I created the first one for a table Book but it will take a lot of time to create SqliteHelper's for all the other tables. Commented Jan 10, 2015 at 20:12
  • Good luck. When you ask questions here, post also stuff that you have tried, or relevant links you have found. This will help us help you faster. Also you will less likely be down voted. Read the FAQ maybe. Commented Jan 10, 2015 at 20:17
  • Don't create multiple helpers. Just one per database file, with all tables in one helper. Commented Jan 11, 2015 at 8:12

1 Answer 1

1

If you have that many tables, I would suggest you to use an ORM instead of creating the Sqlite helpers by yourself. The two most popular ones are currently ORMLite and GreenDAO. They allow you to write nice code like this (example taken from the ORMLite home page) :

@DatabaseTable(tableName = "accounts")
public class Account {
    @DatabaseField(id = true)
    private String name;

    @DatabaseField(canBeNull = false)
    private String password;
}

The ORM does all the work, you just create a class with some fields and it will bind them to a database automatically without having to write a single line of SQL.

Sign up to request clarification or add additional context in comments.

5 Comments

I guess that it's like JPA in javaEE?
@asa Yes, JPA is an ORM (object relational mapping). Just know that the android ORMs support much less advanced features than JPA. But you can always use raw SQL queries.
I will use ORMLite then ;) Thank you !
Can we generate pojo classes from tables with ORMLite like we can do with JPA tools??
I generate all the entities i need using JPA and now i will change JPA's annotations with ORMLite's annotations

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.