我是SQLite的新手。我正在尝试在Android中使用SQLite。但是我在运行它时遇到了这种错误。
错误:
准备时,0x14d2c8出现故障1(在“ tableuserInfoTable”附近:语法错误)
'create tableuserInfoTable(_id integer primary key name text not nullemailtext not nullpasswordtext not nulltimetext not null);'
。
代码:
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回顾了几乎每个示例,但我无法弄清楚。谢谢
试试这个
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);";
几个错误:-您缺少table和tableName之间的空格;-您缺少列末尾的逗号,-您还缺少列名与数据类型之间的空格:
您应该始终记录查询并尝试直接在数据库中运行它。错误将很快被清除。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句