Android - SQLite创建表错误

时间:2012-04-06 17:56:30

标签: android sqlite

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

这是我的表(在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 个答案:

答案 0 :(得分: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);";

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

答案 1 :(得分:0)

您需要用分号分隔那里的两个SQL语句。

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

答案 2 :(得分: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," +

“得分文本不为空,难度文本不为空,日期日期不为空”

我现在检查它工作正常

答案 3 :(得分: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);";
是的,也放了;最后,格雷厄姆说。