Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT</strong></p> <p>My original answer is wrong when stating that the <code>onCreate</code> method is called every time the <code>SQLiteOpenHelper</code> (<code>dbhelper</code> in this case) is created. According to <a href="http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html" rel="nofollow noreferrer">documentation</a> it's only called when the database is created (thanks, @KumarBibek, for bringing this to my attention). This also means that my answer is pretty much useless, as of the reported issue at least. I still choose to keep it alive, partly as a shameful reminder of my hasty mistake :-) but also as it (according to me) has some other useful side notes for any future readers.</p> <p><strong>ORIGIN</strong></p> <p>Regardless of your current issue, I think you'll meet other problems as well if you try to create your table in the <code>onCreate</code> method. Unless you somehow delete your table (in the corresponding <code>onDestroy</code> or something) then you'll try to execute a <code>CREATE TABLE...</code> query on a table that already exists for every time the <code>dbhelper</code> class is "created" by the platform. Your current problem might actually even be because of that (even if I find it a bit unlikely, due to the stated error message).</p> <p>There is a <code>onUpgrade</code> and <code>onDowngrade</code> method in the <code>SQLiteOpenHelper</code> (which I assume you're extending) where the <code>onUpgrade</code> method would be a much more suitable place to create your table, but again: you'll need to delete it before or only execute the create statement for the first version (add an if-check on the <code>newVersion</code> method parameter). Alternatively you could <a href="http://www.sqlite.org/lang_createtable.html" rel="nofollow noreferrer">add a <code>IF NOT EXISTS</code> escape sequence</a>, so that your create statement would look something like <code>CREATE TABLE IF NOT EXISTS Employee...</code>.</p> <p>If you create an in-memory database this is not an issue (but then your <a href="http://www.sqlite.org/inmemorydb.html" rel="nofollow noreferrer">database file name would begin with a colon</a>, like ":Employee.db"). Be aware, though, that all your data will get deleted as soon as your in-memory database is released.</p> <p>Yet another tip: You can actually test your SQL syntax in an online SQL syntax validator (one example is presented <a href="https://webapps.stackexchange.com/questions/14491/online-sql-statement-checker">here</a>, make sure you choose the correct SQL engine, "SQLite", in the toolbar). These kind of tools will validate your <em>SQL syntax</em>. They can, however, not validate the <em>logical</em> validity (i.e. errors due to misuse of the Android life cycle).</p> <p>One other side-note is that class names should, as of unwritten old-school java standard, begin with upper-case letters. Hence, your <code>dbhelper</code> class (and thereby also your constructor) should actually read <code>Dbhelper</code> or even nicer <code>DbHelper</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload