故障1:语法错误 [英] Failure 1:Syntax error

查看:151
本文介绍了故障1:语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQLite的一个新的。我想在Android中使用的SQLite。但我面临这样那样的错误,当我运行它。

I am a new in SQLite. I am trying to use SQLite in Android. But I am facing this kind of error when I run it.

错误:

故障1(近tableuserInfoTable:语法错误)上0x14d2c8时preparing 创建tableuserInfoTable(_id整数主键名文本不nullemailtext不nullpasswordtext不nulltimetext NOT NULL);

Failure 1 (near "tableuserInfoTable": syntax error) on 0x14d2c8 when preparing 'create tableuserInfoTable(_id integer primary key name text not nullemailtext not nullpasswordtext not nulltimetext not null);'.

code:

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DBHelper extends SQLiteOpenHelper {
    public static final String DATABASE_NAME="data";
    public static final int DATABASE_VERSION=1;

    public static final String USER_TABLE="userTable";
    public static final String C_ID="_id";
    public static final String USER="name";
    public static final String EMAIL="email";
    public static final String PASSWORD="password";
    public static final String TIME="time";

    public final String createDB="create table"+USER_TABLE+"("+C_ID+" integer primary key "
                             +USER+" text not null"  +EMAIL+ "text not null" +PASSWORD+ "text not null" 
                             +TIME+ "text not null);";

    public DBHelper(Context context)
    {
        super(context,DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL(createDB);
    }


@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub
    if (newVersion > oldVersion) {
        Log.w("MyAppTag","Updating database from version " + oldVersion + " to "
                + newVersion + " .Existing data will be lost.");
  db.execSQL("drop table if exists"+USER_TABLE);
  onCreate(db);
}
}  
 }

我走过去,几乎每一个例如,从SO,但我不明白这一点。
谢谢

I went over almost every single example from SO,but I couldn't figure that out. Thank you

推荐答案

试试这个

public final String createDB="create table "+USER_TABLE+"("
                         +C_ID+" integer primary key, "
                         +USER+" text not null,"  
                         +EMAIL+ " text not null," 
                         +PASSWORD+ " text not null," 
                         +TIME+ " text not null);";

一对夫妇的错误:
  - 你缺少表和表名之间的空间;
  - 你缺少逗号在列的末尾,
  - 你也缺少列名和数据类型之间的空间:

A couple of errors: - You are missing a space between table and the tableName; - You are missing the commas at the end of the columns, - You are also missing spaces between the column names and the data types:

您应该随时登录查询,并尝试在数据库中直接运行它。这些错误会很快清楚。

You should always log your query and try to run it in the database directly. The errors will become clear very quickly.

这篇关于故障1:语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆