我已准备好在SQLITE ANDROID STUDIO中创建数据库和表的代码,但我在SQL语句中遇到错误。
错误图片在这里: - ERROR IMAGE
package com.example.thakkar.registration;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.view.View;
public class DataBaseHelper extends SQLiteOpenHelper {
public static final String DATABASAE_NAME="student.db";
public static final String TABLE_NAME="student_table";
public static final String COL_1="NAME";
public static final String COL_2="EMAIL";
public static final String COL_3="PASSWORD";
public DataBaseHelper(Context context) {
super(context, DATABASAE_NAME, null, 1);
SQLiteDatabase db=this.getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table"+ TABLE_NAME+ "(NAME TEXT,EMAIL TEXT,PASSWORD TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
db.execSQL("DROP TABLE IF EXIST"+ TABLE_NAME);
onCreate(db);
}
}
答案 0 :(得分:3)
您需要在table
之前将TABLE_NAME
与空格分开,
像,
db.execSQL("create table "+ TABLE_NAME+ "(NAME TEXT,EMAIL TEXT,PASSWORD TEXT)");
在onUpgrade()
方法中也一样,
db.execSQL("DROP TABLE IF EXISTS "+ TABLE_NAME);