0

i'm trying to insert some data into a SQLite3 Database on an Android system.

This method should takes three strings and insert them into a database:

public void createEntry(String description, String reps, String weight) 
{
    ContentValues cv = new ContentValues(); 
    cv.put(KEY_DESCRIPTION, description);
    cv.put(KEY_REPS, reps);
    cv.put(KEY_WEIGHT, weight);
    sqlDB.insert(DATABASE_TABLE, null, cv);     
}

The columns(KEY_DESCRIPTION,..) are all defined as TEXT NOT NULL and I also added an auto incrementing column.

In my main activity I'm using this code to get input from EditText Widgets

String description = sqlDescription.getText().toString();

then I'm creating an instance of my DB class:

            DB entry = new DB(MainActivity.this);
            entry.open();
            entry.createEntry(description, reps, weight);
            entry.close();

open() uses the SQLiteOpenHelper and sets up database:

public DB open()
{
    sqlHelper = new dbHelper(sqlContext);
    sqlDB = sqlHelper.getWritableDatabase();
    return this;
}

But when I call this method:

entry.createEntry(description, reps, weight);

I get following error:

(1) near "Table": syntax error

E/SQLiteDatabase(19344): Error inserting Description=test Weight=tesz Reps=test

E/SQLiteDatabase(19344): android.database.sqlite.SQLiteException: near "Table": syntax error

(code 1): , while compiling: INSERT INTO Table(Description,Weight,Reps) VALUES (?,?,?)

2
  • Please share the value of DATABASE_TABLE String Commented Jan 26, 2014 at 13:17
  • private static final String DATABASE_TABLE = "Table"; Commented Jan 26, 2014 at 13:20

1 Answer 1

2

TABLE is a reserved word in SQL; you should not use it as the name of the table.

Try changing it to:

private static final String DATABASE_TABLE = "myTable";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.