Reputation: 780
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();
}`
Upvotes: 0
Views: 2430
Reputation: 3370
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
Upvotes: 0
Reputation: 15847
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
Upvotes: 0
Reputation: 68187
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
Upvotes: 1
Reputation: 23398
You need to separate the two SQL statements in there with a semicolon.
... theme text not null); " + <-- semi colon added here
"create table score ...
Upvotes: 0