在android中的sqlite db中插入数据时出错

时间:2017-03-17 01:25:04

标签: java android sqlite

  

引起:android.database.sqlite.SQLiteException:near" Group":   语法错误(代码1):,编译时:CREATE TABLE   contact_info(姓名TEXT,PhoneNumber TEXT,Email TEXT,Address TEXT,Group   TEXT,Image BLOB); >错误代码:1(SQLITE_ERROR)>引起:SQL(查询)错误或缺少数据库。 > (接近" Group&#34 ;:语法错误(代码1):,同时编译:CREATE TABLE   contact_info(姓名TEXT,PhoneNumber TEXT,Email TEXT,Address TEXT,Group   TEXT,Image BLOB);)

DatabaseOperations.java

public class DatabaseOperations extends SQLiteOpenHelper {
public static final int database_version=1;
    public String CREATE_QUERY="CREATE TABLE "+ TableData.TableInfo.TABLE_NAME+"("+ TableData.TableInfo.NAME+" TEXT,"+ TableData.TableInfo.PHONE_NUMBER+" TEXT,"+TableData.TableInfo.EMAIL+" TEXT,"+TableData.TableInfo.ADDRESS+" TEXT,"+TableData.TableInfo.GROUP+" TEXT,"+TableData.TableInfo.IMAGE+" BLOB);";

//create database
    public DatabaseOperations(Context context) {
                super(context, TableData.TableInfo.DATABASE_NAME,null,database_version);
                Log.d("Database Operations","Database created");

    }

    @Override
    public void onCreate(SQLiteDatabase db) {
       //create table
     db.execSQL(CREATE_QUERY);
        Log.d("Database opertaions","Table created");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
       db.execSQL("DROP TABLE IF EXISTS"+TableData.TableInfo.TABLE_NAME);
    }

    public void putInfo(SQLiteDatabase sdb, String name, String phoneNumber,String email,String address,String group,String image)
    {

        ContentValues cv = new ContentValues();

        cv.put(TableData.TableInfo.NAME,name);
        cv.put(TableData.TableInfo.PHONE_NUMBER,phoneNumber);
        cv.put(TableData.TableInfo.EMAIL,email);
        cv.put(TableData.TableInfo.ADDRESS,address);
        cv.put(TableData.TableInfo.GROUP,group);
        cv.put(TableData.TableInfo.IMAGE,image);

        long k= sdb.insert(TableData.TableInfo.TABLE_NAME,null,cv);
        Log.d("Database operations","One row inserted"+k);
    }

0 个答案:

没有答案