(1) near “existsUserInformation”: syntax error

匿名 (未验证) 提交于 2019-12-03 01:09:02

问题:

public class DataBaseClass extends SQLiteOpenHelper {      public static final String DB_NAME = "USER DATA";     public static final int DB_VERSION = 1;      public static final String TABLE_NAME_USERSINFO = "UserInformation";     public static final String COLUMN_NAME_FIRSTNAME = "FirstNamestring";     public static final String COLUMN_NAME_LASTNAME = "LastNamestring";     public static final String COLUMN_NAME_ADD1 = "Add1string";     public static final String COLUMN_NAME_ADD2 = "Add2string";     public static final String COLUMN_NAME_SSNFRST ="SSnfirststring";     public static final String COLUMN_NAME_SSNLST = "SSnlaststring";     public static final String COLUMN_NAME_MOBNO = "ContactNostring";     public static final String COLUMN_NAME_EMAILID = "emailidstring";     public static final String COLUMN_NAME_DOB = "Dateofbirthstring";      public DataBaseClass(Context context) {         super(context, DB_NAME, null, DB_VERSION);         // TODO Auto-generated constructor stub      }      @Override     public void onCreate(SQLiteDatabase db) {         // TODO Auto-generated method stub         String sqlQueryToCreateUserInformation = "create table if not exists" + TABLE_NAME_USERSINFO +                 "(" + BaseColumns._ID + "integer primary key autoincrement,"                 + COLUMN_NAME_FIRSTNAME + " text not null,"                 + COLUMN_NAME_LASTNAME + " text not null,"                 + COLUMN_NAME_ADD1 + " text not null,"                 + COLUMN_NAME_ADD2 + " text not null,"                 + COLUMN_NAME_SSNFRST + " text not null,"                 + COLUMN_NAME_SSNLST + " text not null,"                 + COLUMN_NAME_MOBNO + " text not null,"                 + COLUMN_NAME_EMAILID + " text not null,"                 + COLUMN_NAME_DOB + " text not null,"                 + ");";         db.execSQL(sqlQueryToCreateUserInformation);      }      public void insertForm(String FirstNmstring, String LastNmstring,              String Add1string ,String Add2string,String SSnfirststring,             String SSnlaststring, String ContactNostring, String emailidstring, String Dateofbirthstring) {          String sqlQueryToCreateUserInformation;          ContentValues cv=new ContentValues();          cv.put(COLUMN_NAME_FIRSTNAME,FirstNmstring);         cv.put(COLUMN_NAME_LASTNAME, LastNmstring);         cv.put(COLUMN_NAME_ADD1, Add1string);         cv.put(COLUMN_NAME_ADD2, Add2string);         cv.put(COLUMN_NAME_SSNFRST, SSnfirststring);         cv.put(COLUMN_NAME_SSNLST, SSnlaststring);         cv.put(COLUMN_NAME_MOBNO, ContactNostring);         cv.put(COLUMN_NAME_EMAILID, emailidstring);         cv.put(COLUMN_NAME_DOB, Dateofbirthstring);          getWritableDatabase().insert("USER DATA", null, cv);          } 

I am executing this code to store my data in SQLite database built in Android phones. When I am executing my code, I am getting an error message that is "(1) near "existsUserInformation": syntax error"

Kindly help me out with this.

回答1:

You are missing a space in your string concatenation:

"create table if not exists" + TABLE_NAME_USERSINFO 

results in the string

"create table if not existsUserInformation". 

Just add a space after exists:

"create table if not exists " + TABLE_NAME_USERINFO. 

You also have an extra comma at the end of your statement.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!