SQLiteException:无法识别的令牌

时间:2014-06-17 17:28:40

标签: android database sqlite

我在我的应用程序中创建了一个SQLite数据库。我试图在TextView(android)中显示内容,但我对此有任何问题。

数据库:

CREATE TABLE "1_BASICA_1500" ("INDICACIONES" TEXT, "LUNES" TEXT, "MARTES" TEXT,
"MIERCOLES" TEXT, "JUEVES" TEXT, "VIERNES" TEXT, "SABADO" TEXT, "DOMINGO" TEXT,
"_ID" NUMERIC PRIMARY KEY  NOT NULL )"

我的Database.class

public class MyDataBase extends SQLiteAssetHelper {
  private static final String DATABASE_NAME = "dietas.sqlite";
  private static final int DATABASE_VERSION = 1;

  public MyDataBase(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }

  public Cursor getDieta() {

    SQLiteDatabase db = getReadableDatabase();
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

    String [] sqlSelect = {"INDICACIONES", "LUNES", "MARTES", "MIERCOLES", "JUEVES", "VIERNES", "SABADO", "DOMINGO","_ID"}; 
    String sqlTables = "1_BASICA_1500";

    qb.setTables(sqlTables);
    Cursor c = qb.query(db, sqlSelect, null, null,
            null, null, null);

    c.moveToFirst();
    return c;

  }
}

显示内容的类:

public class DietaFragment extends Fragment {
  Bundle paquete;
  TextView txtDieta;
  String nombre;
  MyDataBase db;
  Cursor cursor;

  public DietaFragment(Bundle pack) {
    // TODO Auto-generated constructor stub
    paquete = pack;
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_dieta, container, false);
    txtDieta = (TextView) rootView.findViewById(R.id.txtDieta);
    db = new MyDataBase(this.getActivity());

    cursor = db.getDieta();

    //nombre = paquete.getString("nombre");

    txtDieta.setText(cursor.getString(0));
    return rootView;
  }
}

这是错误:

06-17 12:02:58.933: W/System.err(1630): android.database.sqlite.SQLiteException:
unrecognized token: "1_BASICA_1500" (code 1): , while compiling: SELECT INDICACIONES,
LUNES, MARTES, MIERCOLES, JUEVES, VIERNES, SABADO, DOMINGO, _ID FROM 1_BASICA_1500

如果可以帮助我,请感谢您的观看!

1 个答案:

答案 0 :(得分:4)

表名不能以数字开头,除非您使用转义符号。

尝试

String sqlTables = "[1_BASICA_1500]";