2013-12-07 5 views
2

저는 SQLite에 새로 추가되었습니다. Android에서 SQLite를 사용하려고합니다. 그러나 나는 그것을 실행할 때 이런 종류의 오류에 직면하고있다.오류 1 : 구문 오류

오류 :

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);' .

코드 :

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부터 거의 모든 하나의 예를 갔다,하지만 난 알아낼 수 없었다. 감사합니다.

답변

3

을 시도해보십시오이

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);"; 

오류의 몇 : - 당신은 테이블과 TABLENAME 사이에 공백을 누락; - 열의 끝에 쉼표가 누락되었습니다. - 열 이름과 데이터 형식 사이에 공백이 없습니다.

항상 쿼리를 기록하고 데이터베이스에서 직접 실행해야합니다. 오류는 매우 빨리 사라집니다.

+0

+1 공백을 알리는 데 사용되었습니다. – gahfy

+0

지금 작동 중입니다. 다들 감사 해요. –

3

검색어에 쉼표가없고 공백을 입력하지 않았습니다.

시도 :

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);"; 
+1

은 "CREATE TABLE"및 테이블의 이름 사이에는 공백도 없다. –

+0

고지 해 주셔서 감사합니다. 결정된. – gahfy

0

create tableuserInfoTable(_id integer primary key name text not nullemailtext not nullpasswordtext not nulltimetext not null);을 준비 할 때 0x14d2c8의 오류 1 ("tableuserInfoTable"근처 : 구문 오류).

  • 이 오류 유형에는 tablename (잘못되었을 경우)이 없거나 쉼표와 공백 또는 데이터 유형이 없습니다.

솔루션 테이블 이름 tableuserInfoTable 다음 시작 쿼리 인 경우 :

create table tableuserInfoTable(
_id integer primary key name text not null, 
email text not null, 
password text not null, 
time text not null); 
관련 문제