I'm having a separate web service to get the data (txt data + image URL to download the images) required for the application, this is the only service I’ve in my application, I’m calling this service at the application launch and set up the SQLite Data base (using the ORMLite), once everything is complete user can go to the home screen, so in next launch if the data is in the data base this service not going to call. So far everything is worked fine.
My Question is how I can build this SQLite DB outside the android app and bundle the SQLite data base file to the app; I'm using maven to build the android app.
Do I need to have a separate android project to call the web service and build the SQLite DB or can I use the java project to build the SQLite Db,
If I use the android project how do I get the data base file?
How do I instruct maven to run the above project and copy the db file to android app.
I've start with a maven project, following is snap of my pom xml file
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-core</artifactId>
<version>4.41</version>
</dependency>
<dependency>
<groupId>com.j256.ormlite</groupId>
<artifactId>ormlite-jdbc</artifactId>
<version>4.41</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.6.16</version>
</dependency>
</dependencies>
I'm getting following exception when i try to insert the data to the DB.
at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:124)
at com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:363)
at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:306)
Caused by: java.sql.SQLException: NYI
at org.sqlite.Conn.prepareStatement(Conn.java:443)
at com.j256.ormlite.jdbc.JdbcDatabaseConnection.insert(JdbcDatabaseConnection.java:147)
at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:89)
... 4 more
my Domain Objects
@DatabaseTable
public class Widget implements Comparable<Widget>{
@DatabaseField(id = true)
private String id = null;
@DatabaseField
private String title = null;
....More fileds.
@ForeignCollectionField
private ForeignCollection<WidgetAttribute> db_widget_attribute;
@DatabaseField(canBeNull = true, foreign = true)
private AdvancedSettings advanced_settings = null;
... Getters /setters....
}
@DatabaseTable
public class WidgetAttribute {
@DatabaseField(id = true)
private String id = null;
@DatabaseField
private String value = null;
....More fileds.
@DatabaseField(foreign=true,foreignAutoRefresh=true)
private Widget widget;
... Getters /setters....
}
@DatabaseTable
public class AdvancedSettings {
@DatabaseField(id = true)
private String id = null;
public static final String DB_COLUMN_SHOW_AS_TAB_BAR = "show_as_tab_bar";
@DatabaseField
private String show_as_tab_bar = null;
....More fileds
@DatabaseField(canBeNull = true, foreign = true)
private AdvancedSettingsImages advanced_settings_images = null;
@DatabaseField(foreign=true,foreignAutoRefresh=true)
private Widget widget;
public String getId() {
return id;
}
... Getters /setters....
}
@DatabaseTable
public class AdvancedSettingsImages {
@DatabaseField(generatedId=true)
private int id;
....More fileds
@DatabaseField(canBeNull = true, foreign = true)
private AdvancedSettings advancedSettings = null;
... Getters /setters....
}
when i run the app i see the following log messages in the console
DEBUG [com.j256.ormlite.dao.DaoManager] created dao for class class com.xxx.domain.Widget with reflection
DEBUG [com.j256.ormlite.dao.DaoManager] created dao for class class com.xxx.domain.WidgetAttribute with reflection
DEBUG [com.j256.ormlite.dao.DaoManager] created dao for class class com.xxx.domain.AdvancedSettings with reflection
DEBUG [com.j256.ormlite.dao.DaoManager] created dao for class class com.xxx.domain.AdvancedSettingsImages with reflection
INFO [com.j256.ormlite.table.TableUtils] creating table 'widget'
INFO [com.j256.ormlite.table.TableUtils] executed create table statement changed 0 rows: CREATE TABLE IF NOT EXISTS `widget` (`id` VARCHAR , `title` VARCHAR , `widget_type_id` VARCHAR , `app_xxx_id` VARCHAR , `created_at` VARCHAR , `updated_at` VARCHAR , `position` VARCHAR , `group_widget` VARCHAR , `parent_id` VARCHAR , `image_link` VARCHAR , `advanced_settings_id` VARCHAR , `widgets_id` INTEGER NOT NULL , PRIMARY KEY (`id`) )
INFO [com.j256.ormlite.table.TableUtils] creating table 'widgetattribute'
INFO [com.j256.ormlite.table.TableUtils] executed create table statement changed 0 rows: CREATE TABLE IF NOT EXISTS `widgetattribute` (`id` VARCHAR , `value` VARCHAR , `attribute_type` VARCHAR , `name` VARCHAR , `created_at` VARCHAR , `updated_at` VARCHAR , `image_link` VARCHAR , `widget_id` VARCHAR , PRIMARY KEY (`id`) )
INFO [com.j256.ormlite.table.TableUtils] creating table 'advancedsettings'
INFO [com.j256.ormlite.table.TableUtils] executed create table statement changed 0 rows: CREATE TABLE IF NOT EXISTS `advancedsettings` (`id` VARCHAR , `show_widget_on_home_screen` VARCHAR , `highlight_cell` VARCHAR , `hide_menu` VARCHAR , `show_as_tab_bar` VARCHAR , `icon_color` VARCHAR , `live_tile` VARCHAR , `text_color` VARCHAR , `vertical_alignment` VARCHAR , `horizontal_alignment` VARCHAR , `created_at` VARCHAR , `updated_at` VARCHAR , `advanced_settings_images_id` INTEGER , `widget_id` VARCHAR , PRIMARY KEY (`id`) )
INFO [com.j256.ormlite.table.TableUtils] creating table 'advancedsettingsimages'
INFO [com.j256.ormlite.table.TableUtils] executed create table statement changed 0 rows: CREATE TABLE IF NOT EXISTS `advancedsettingsimages` (`id` INTEGER PRIMARY KEY AUTOINCREMENT , `tab_bar_icon` VARCHAR , `tab_bar_icon_on_press` VARCHAR , `widget_icon` VARCHAR , `widget_icon_on_press` VARCHAR , `advancedSettings_id` VARCHAR )
java.sql.SQLException: Unable to run insert stmt on object
at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:124)
at com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:352)
at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:306)
Caused by: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near ")": syntax error)
at org.sqlite.DB.newSQLException(DB.java:374)
at org.sqlite.DB.newSQLException(DB.java:378)
at org.sqlite.DB.throwex(DB.java:365)
at org.sqlite.NativeDB.prepare(Native Method)
at org.sqlite.DB.prepare(DB.java:123)
at org.sqlite.PrepStmt.<init>(PrepStmt.java:44)
at org.sqlite.Conn.prepareStatement(Conn.java:403)
at org.sqlite.Conn.prepareStatement(Conn.java:398)
at org.sqlite.Conn.prepareStatement(Conn.java:382)
at org.sqlite.Conn.prepareStatement(Conn.java:386)
at com.j256.ormlite.jdbc.JdbcDatabaseConnection.insert(JdbcDatabaseConnection.java:147)
at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:89)
... 4 more
Can some one help me to fix the above issue.