Insert returns -1 with SQLite
<p>I have been struggling with this for hours. My SQLite insert always returns -1 ...</p>

<p>Here is my code from the main activity in one file that calls my db code in another file:</p>

<p>public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);</p>

<pre><code>    jobsdb = new NotifyJobsDBAdapter(this);
    jobsdb.open();

    currentjobid = 1;
    currentjob = new Job(currentjobid, "Starting Tele Num", "Starting Text Msg");
    currentjobid = jobsdb.insertJob(currentjob);
   // this last statement returns -1
}
</code></pre>

<p>This is my db adaptor code in another file:</p>

<p>public class NotifyJobsDBAdapter {</p>

<pre><code>private static final String DB_NAME = "notifyjobsdb";
private static final String DB_TABLE = "notifyjobs";
private static final int DB_VERSION = 1;
private final Context ctx;

// Database column names
private static final String JOB_ID = "jobid";
private static final String JOB_TELE = "contactnumber";
private static final String JOB_TEXT = "textmessage";

private SQLiteDatabase notifyjobsdb;
private NotifyJobsDatabaseHelper dbHelper;
private boolean openness;
private boolean err;
private boolean err0;
private int cnt;
private int i1;
private String s1;
private String s2;
private static String s3;
private int res;
private SQLiteException ex0;
private SQLiteException ex1;

private static class NotifyJobsDatabaseHelper extends SQLiteOpenHelper {

    private static final String DATABASE_CREATE = 
        "CREATE TABLE IF NOT EXISTS " + DB_TABLE +
        " (+ " + JOB_ID + "INTEGER PRIMARY KEY, " +
        JOB_TELE + "TEXT NOT NULL, " +
        JOB_TEXT + "TEXT NOT NULL);";

    private static final String DATABASE_UPGRADE = 
        "DROP TABLE IF EXISTS notifyjobs ";

    public NotifyJobsDatabaseHelper(Context _context) {
        super(_context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(DATABASE_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL(DATABASE_UPGRADE);
                }

}

public NotifyJobsDBAdapter(Context _context) {
    this.ctx = _context;
}

public void open() { 
    dbHelper = new NotifyJobsDatabaseHelper(ctx);
    try { notifyjobsdb = dbHelper.getWritableDatabase();
    } catch(SQLiteException ex) {
        ex0 = ex;
    }

}  

public void close() {
    notifyjobsdb.close();
}
</code></pre>

<p>// this is my problem method</p>

<pre><code>public int insertJob(Job _job) {
    ContentValues newJobValues = new ContentValues();
    newJobValues.put(JOB_ID, _job.getjobid());
    newJobValues.put(JOB_TELE, _job.gettelenum());
    newJobValues.put(JOB_TEXT, _job.gettextmsg());
    notifyjobsdb.beginTransaction();
    // res is always returned a -1
    try {
    res = (int) notifyjobsdb.insertOrThrow(DB_TABLE, null, newJobValues);
    } catch (SQLiteException ex) {
        ex1 = ex;
    }

    notifyjobsdb.setTransactionSuccessful(); 
    close();
    return res;
</code></pre>

<p>Here, res is always -1 and the debugger shows the detailmessage for ex1 as </p>

<p>"no such table: notifyjobs: , while compiling: INSERT INTO notifyjobs(contactnumber, textmessage, jobid) VALUES(?, ?, ?);</p>

<p>I would appreciate any help!</p>
