Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3315062
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:18:21+00:00 2026-05-17T22:18:21+00:00

I have been struggling with this for hours. My SQLite insert always returns -1

  • 0

I have been struggling with this for hours. My SQLite insert always returns -1 …

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

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

    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
}

This is my db adaptor code in another file:

public class NotifyJobsDBAdapter {

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();
}

// this is my problem method

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;

Here, res is always -1 and the debugger shows the detailmessage for ex1 as

“no such table: notifyjobs: , while compiling: INSERT INTO notifyjobs(contactnumber, textmessage, jobid) VALUES(?, ?, ?);

I would appreciate any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:18:22+00:00Added an answer on May 17, 2026 at 10:18 pm

    It is necessary to name the primary id field of your tables “_id” so Android will know where to bind the id field of your tables. So I suggest you try to name your ID columns “_id” instead of “jobid”.

    Also, I suggest not to use transactions where you do only one operation (you can later on decide to wrap multiple insert into a transaction).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with getting this query right for hours now. I have
I have been struggling for a couple hours now with serving jpg's with a
I've been struggling with this for a few hours. Everything just stopped working and
I have been struggling with this for several days now and I ran out
I am writing my first Android application, and I have been struggling with this
I know there are a lot of other SO entries that seem like this
gleanings from a variety of sources (including stackOverlflow), however when I come to use
I feel foolish asking such a fundamental question but it would be more foolish
I am trying to create a timesheet application in MVC 2, but I feel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.