jdbc - SQLite exception on Windows and not Mac OSX -


i'm developing mac os x java application uses sqlite database using jdbc driver.

the code works fine on mac, can't use batch inserts using preparedstatements on windows box.

edit: doesn't work simple statements contains single insert into instructions (create table works fine).

my code basically:

table creation:

    final string sql = "create virtual table " + table_name + " using fts3("             + key_nom + ", "             + key_prenom + ", "             + key_adresse + ", "             + key_adresse2 + ", "             + key_adresse3 + ");";      try {         final statement s = mconnection.createstatement();         s.execute(sql);     } catch (final sqlexception e) {         l.e("unable create table: "+sql+"! "+e);     } 

preparedstatement creation:

    string sql =             "insert "+table_name                     +" ("                     + key_nom + ", "                     + key_prenom + ", "                     + key_adresse + ", "                     + key_adresse2 + ", "                     + key_adresse3 + ") "                     + " values (?, ?, ?, ?, ?)";      mconnection.setautocommit(false);     final preparedstatement prep = mconnection.preparestatement(sql); 

then there loop parses csv file, , @ each line following code called:

        int = 1;         prep.setstring(i++, ""+lawyer.nom);         prep.setstring(i++, ""+lawyer.prenom);         prep.setstring(i++, ""+lawyer.adresse);         prep.setstring(i++, ""+lawyer.adresse2);         prep.setstring(i++, ""+lawyer.adresse3);         prep.addbatch(); 

when parsing of csv file over, following executed:

        final int[] res = prep.executebatch();         mconnection.setautocommit(true);         (int r: res) {             if (r != 1) {                 l.e("error adding entry!");             }         } 

when call mconnection.setautocommit(true);, inserts statements executed when raises following exception:

java.sql.sqlexception: sql logic error or missing database @ org.sqlite.db.throwex(db.java:288) @ org.sqlite.db.exec(db.java:68) @ org.sqlite.conn.setautocommit(conn.java:166) 

tested environments:

  • macbookair - mac os 10.6 - x64 - java 1.6.31 - works fine (my development station)
  • laptop - windows 7 - x64 - java 1.6.30 - works fine
  • macbook - mac os 10.5 - x64 - java 1.6.26 - works fine
  • desktop - windows vista - x86 - java 1.? - doesn't work
  • server - windows server 2003 - unknown arch, x86 guessed - java 1.7 - doesn't work
  • desktop - windows 7 - x86 - java 1.7 - doesn't work
  • desktop - windows xp - x86 - java 1.6.31 - doesn't work

it seems x64 hosts can make work. following jars used:

  • swt : included x64 version on x64 hosts, , x86 version on x86 hosts
  • sqlitejdbc-v056: apparently x86 , x64 compatible
  • opencsv: doesn't contain native code
  • itext-2.1.7 , itextrtf: doesn't contain native code

so maybe jdbc sqlite driver isn't x86-compatible. i'll try investigate more.

tl;dr:
sqlite jdbc driver using native code , not compatible 32 bits processors.

two possible fixes:

  • use xerial, native sqlite jdbc driver works fine on both mac os x 64 bits , windows 32 bits
  • use pure java implementation fixed issue, @ cost of performance.

explanation:

i've spent past 3 days banging head wall sqlite exception saying "sql logic error or missing database". won't comment on exception text includes 2 possible, different errors without saying cause. won't comment either on fact none of 2 errors mentioned in exception text cause of issue.

facts:

  • sqlite exception stating "sql logic error or missing database"
  • using jsqlitejdbc v056
  • the driver able create tables
  • the driver able select information tables
  • the database file not corrupted, ie. possible open sqlite client , insert data tables
  • the driver unable insert data tables

what solved issue replace sqlitejdbc-v056.jar contains native code sqlitejdbc-v056-pure.jar pure-java implementation.

i hope users had issue able see this, , not lose 3 days on this.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -