2013-10-22 4 views
0

오류가 설치 DATABASE_CREATE 방식에 있다고 생각합니다. 내가 여기서 뭔가를 놓치고 있니? 나는 긴 id = -1 SQLiteException지고 있어요. 충분한 세부 정보를 제공하는지 알려주세요. KEY_ID = "_id"설정을 시도했습니다.SQLiteException : 데이터베이스에 삽입하는 동안 오류가 발생했습니다 : 구문 오류 (코드 1)

E/SQLiteLog(2385): (1) near "group": syntax error 
E/SQLiteDatabase(2385): Error inserting group=demo 
E/SQLiteDatabase(2385): android.database.sqlite.SQLiteException: near "group": syntax error (code 1): , while compiling: INSERT INTO groups(group) VALUES (?) 
LOG(2385): Inserting record... 
LOG(2385): mGroupName = demo 
LOG(2385): long id = -1 

DBAdapter.java

public static final String KEY_ID = "id"; 
public static final String KEY_GROUP_NAME = "group"; 
public static final String TAG = "DBAdapter"; 
public static final String DATABASE_NAME = "GroupsDB"; 
public static final String DATABASE_TABLE = "groups"; 
public static final int DATABASE_VERSION = 1; 
private static final String DATABASE_CREATE = "create table if not exists groups (id integer primary key autoincrement, group VARCHAR not null);"; 

. . .

//---insert a record into the database 
public long insertRecord(String group) { 
    ContentValues initialValues = new ContentValues(); 
    initialValues.put(KEY_GROUP_NAME, group); 
    return db.insert(DATABASE_TABLE, null, initialValues); 
} 

MainActivity.java

EditText groupNameText = (EditText) findViewById(R.id.groupNameEditText); 
String mGroupname = groupNameText.getText().toString(); 

...

   try { 
        String destPath = "/data/data/" + getPackageName() + "/databases/GroupsDB"; 
        File f = new File(destPath); 
        if(!f.exists()) { 
         CopyDB(getBaseContext().getAssets().open("mydb"), 
         new FileOutputStream(destPath)); 
        } 
       }catch (FileNotFoundException e) { 
        e.printStackTrace(); 
       }catch (IOException e) { 
        e.printStackTrace(); 
       } 

       DBAdapter db = new DBAdapter(this); 

       //try hard coding the record here, if unable to insertRecord for any reason it will return -1 
       db.open(); 
       long id = db.insertRecord(mGroupname); 
       Log.i(TAG, "Inserting record..."); 
       Log.i(TAG, "mGroupName = " + mGroupname); 
       Log.i(TAG, "long id = " + id); 
       db.close(); 

답변

5

그룹은 SQLite는 키워드입니다. 참조 : http://www.sqlite.org/lang_keywords.html

변경에 대한 모든 참조에 "그룹을"내 테이블 이름 "그룹": 생각 것 잘못 알아 내려고 시간에 대한 낭비 "mgroup"

+1

같은 것으로. – Hades200621

+0

@ Hades200621처럼 ... 무슨 일이 일어나고 있는지 알지 못하고 1 시간 이상을 낭비했습니다 ... Thanks @ KlassAktKreations! – Seishin

관련 문제