0

准备“创建表选项...创建表分数...我将在我的程序中发布所有其他代码,以便我可以在遇到更多问题时询问(接近“创建”:语法错误)) .

这是我的表(在 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, );";

这是我的 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);
}`

这是我的 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

4 回答 4

1

修正您的查询如下:

"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);";

您错过了分号并在查询中留下了一个额外的逗号

于 2012-04-06T17:59:57.640 回答
0

您需要用分号分隔其中的两个 SQL 语句。

... theme text not null); " +   <-- semi colon added here
"create table score ...
于 2012-04-06T17:58:24.927 回答
0

您的第一个查询没有错误

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," +

“分数文本不为空,难度文本不为空,日期日期不为空)

我已经检查过它现在工作正常

于 2012-04-06T18:00:46.930 回答
0

从末尾删除

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

写如下

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

是的,还有放;最后正如格雷厄姆所说

于 2012-04-06T18:01:02.243 回答