3

I am trying to create a database on android and when I run an exception is raised:

Database - Failure 1 (near "integer" : syntax error) on 0x1ac028 when preparing 'create table list1 (id integer Primary key autoincrement, task text not null, check integer not null)'

I don't understand why this is happening. This is my code:

String dbName="projectDatabase";
    String tableName="List1";
    String TableStructure="create table " + tableName +" (id integer Primary key autoincrement, task text not null, check integer not null)";
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button cb = (Button) findViewById(R.id.creatbutton);
        cb.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                try{
                    SQLiteDatabase ldb = openOrCreateDatabase(dbName, Context.MODE_PRIVATE, null);
                    ldb.execSQL(TableStructure);}catch(Exception e){
                        Toast.makeText(DsTest2Activity.this, "Failed", Toast.LENGTH_LONG).show();
                    }
                Intent list = new Intent(DsTest2Activity.this,List.class);
                startActivity(list);
            }
        });
    }
1
  • i think its check id not null in the create statement. Once check it Commented Nov 21, 2012 at 17:13

3 Answers 3

3

check is an SQLite keyword. You cannot use it as a table or column name.

Change your column name to something else and your error will go away.

String TableStructure="create table " + tableName +" (id integer Primary key autoincrement, task text not null, checknum integer not null)";

For a complete list of curent SQLite keywords, look here.

Sign up to request clarification or add additional context in comments.

Comments

1

To use a keyword directly as a column name, quote it:

..., "check" integer not null)

1 Comment

+1 True, but then you have to escape the quote marks (to use in the method that the OP is using it). Simpler to just change the column name IMO. :p
-1

Good afternoon, put into your code _id integer primary key autoincrement, ..., for exemple:

CREATE TABLE tabela(_id integer primary key autoincrement, task text not null, check integer not null);

1 Comment

check is an SQLite keyword... it cannot be used as a table or column name.

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.