3

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.

  1. 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,

  2. If I use the android project how do I get the data base file?

  3. 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.

Sam
  • 6,215
  • 9
  • 71
  • 90

1 Answers1

0

According to this question ( SQLiteJDBC and PreparedStatement to use pragma table_info ) the NYI means Not-Yet-Implemented and is being thrown by Sqlite while trying to prepare the create SQL statement. This has nothing to do with maven if there is any question.

I'd be interested to see your schema. Maybe there is some sort of custom statements that you are trying to use with Sqlite?

Community
  • 1
  • 1
Gray
  • 115,027
  • 24
  • 293
  • 354
  • i have updated the question with my domain objects, i'm getting the above error when "advanceSettingsimages" object going to persist, all the other objects widget->widget Attributes->Advance settings getting inserted without problem. – Sam Aug 02 '12 at 06:03
  • Is ORMLite creating your schema? Any chance the schema does not match your data? Did you increase the database version number @Sam recently? – Gray Aug 02 '12 at 13:50
  • i can see the create table stmt in the console log, this is initial stage of the project so there no update to the data base version, error occurred when inserting data to the "advancedSettingsImages" if i comment that block all the get inserted, i still could not find out the issue. – Sam Aug 02 '12 at 14:08
  • Can you post the create statement @Sam? – Gray Aug 02 '12 at 14:11
  • Unfortunately it is the next statement that is the problem right? And of course ORMLite is printing out the statements _after_ they execute. Can you debug into that method and find out what the statement is @Sam? – Gray Aug 02 '12 at 15:21
  • I'm using the sqlite-jdbc-3.6.16.jar when i change the sqlite jdbc driver jar to sqlite-jdbc-3.6.20.jar im getting the following error Caused by: java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near ")": syntax error) i have updated the full stack trace in question, which version of the sqlite jdbc jar i should use – Sam Aug 11 '12 at 15:59