0

The error says something like (near "create": syntax error) when preparing 'create table option... create table score... I'll just post all other codes in my program so that I can ask whenever there's more problem encountered.

This is my table (in DBHelper.java):

final static String sqlcreate=

        "create table option (id integer primary key autoincrement," + 
        "volume boolean not null, vibrate boolean not null, theme text not null) " +    

        "create table score (id integer primary key autoincrement," +
        "score text not null, difficulty text not null, date date not null, );";

This is my DBFunction.java:

public int addScore(String score, String difficulty){

ContentValues values = new ContentValues();

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
    Date scoredate = new Date();    
    values.put("score", score);
    values.put("difficulty", difficulty);
    values.put("date", dateFormat.format(scoredate));   
    return (int) db.insert(tableScore, null, values);
}`

And this is my OnClick():

if (v==btnadd){

        String vol = tbtnvol.getText().toString();
        String vib = tbtnvib.getText().toString();
        String theme = themename.getText().toString();
        options.open();
        options.addOption(vol, vib, theme);
        options.close();
        Toast.makeText(this, "Data has been added", Toast.LENGTH_LONG).show();
    }`

4 Answers 4

1

Fix your query as below:

"create table option (id integer primary key autoincrement," + 
"volume boolean not null, vibrate boolean not null, theme text not null); " +

"create table score (id integer primary key autoincrement," +
"score text not null, difficulty text not null, date date not null);";

You have missed semi-colon and left an extra comma in your query

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

1 Comment

Oh, it is not included in my query, sorry.. It's suppose to be "`", the one that you type here in stackoverflow when writing codes.. I'll just fix that.. I'll try first to separate my table into different variables.
0

You need to separate the two SQL statements in there with a semicolon.

... theme text not null); " +   <-- semi colon added here
"create table score ...

Comments

0

your first Query without error

create table option (id integer primary key autoincrement,volume boolean not null, vibrate boolean not null, theme text not null)

second query

create table score (id integer primary key autoincrement," +

"score text not null, difficulty text not null, date date not null)

i have checked it now it works fine

Comments

0

remove , from end

"create table score (id integer primary key autoincrement," +
    "score text not null, difficulty text not null, date date not null, );";

write as follow

"create table score (id integer primary key autoincrement," +
    "score text not null, difficulty text not null, date date not null);";

yup, and also put ; at end as Graham said

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.