本文介绍了SQLiteException:临近"" :在编译语法错误(code 1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的错误在编译时和我不知道为什么,谁能帮助我?

I have this error while compiling and I don´t know why, can anyone help me?

公共静态最后弦乐TABLE_BEERS =cervezas;

public static final String TABLE_BEERS = "cervezas";

// Contacts Table Columns names
public static final String KEY_NAME = "_id";
public static final String KEY_COMPANY = "company";
public static final String KEY_TYPE = "type";
public static final String KEY_ALCOHOL = "alcohol";


public DatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    // TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {

    String query = String.format("CREATE TABLE %s (%s STRING PRIMARY KEY,%s TEXT, %s TEXT, %s TEXT);",
            TABLE_BEERS, KEY_NAME, KEY_COMPANY,
            KEY_TYPE, KEY_ALCOHOL);

    /*
    String CREATE_BEER_TABLE = "create table " + TABLE_BEERS + "("
            + KEY_NAME + " STRING PRIMARY KEY,"
            + KEY_COMPANY + " TEXT,"
            + KEY_TYPE + " TEXT,"
            + KEY_ALCOHOL + " TEXT )";*/
    db.execSQL(query);

这是创建表

public List<Cervezas> getCompanyCervezas(String compania){

            List<Cervezas> cervezasList = new ArrayList<Cervezas>();
            // Select All Query
            String selectQuery = "SELECT _id, type, alcohol FROM " + TABLE_BEERS + " WHERE company=" + compania;

            SQLiteDatabase db = this.getReadableDatabase();
            Cursor cursor = db.rawQuery(selectQuery, null);

LogCat中

LogCat

android.database.sqlite.SQLiteException: no such column : Alean (code 1): , while compiling: SELECT _id, type, alcohol FROM cervezas WHERE company=Alean

这是怎么回事?

推荐答案

试试下面code: -

try below code:-

String selectQuery = "SELECT _id, type, alcohol FROM " + TABLE_BEERS + " WHERE company= ' " + compania+" ' ";

您错过的单引号。

这篇关于SQLiteException:临近&QUOT;&QUOT; :在编译语法错误(code 1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 06:14