sqlite返回:错误代码= 1,msg =没有这样的列:Bateria

时间:2013-05-10 04:20:02

标签: android sqlite

每次运行

的应用程序时都会出错
  

sqlite返回:错误代码= 1,msg =没有这样的列:Bateria

数据库代码

    public AdminSQLiteOpenHelper(Context context, String nombre,
            CursorFactory factory, int version) {
        super(context, nombre, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table gas(_id integer primary key autoincrement, "
                + "estacion text not null, precio intenger not null, fecomgas text not null)");
        db.execSQL("create table aceite(_id integer primary key autoincrement, "
                + "marcef text not null, precio intenger not null, fecamac text not null)");
        db.execSQL("create table repuestos(_id integer primary key autoincrement, tipo text not null, precio intenger not null, fecomrep text not null)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int versionAnte, int versionNue) {
        db.execSQL("drop table if exists gas");
        db.execSQL("create table gas(_id integer primary key autoincrement, "
                + "estacion text not null, precio intenger not null, fecomgas text not null)");
        db.execSQL("drop table if exists aceite");
        db.execSQL("create table aceite(_id integer primary key autoincrement, "
                + "marcef text not null, precio intenger not null, fecamac text not null)");
        db.execSQL("drop table if exists repuestos");
        db.execSQL("create table repuestos(_id integer primary key autoincrement, tipo text not null, precio intenger not null, fecomrep text not null)");

    }
}

每次调用此方法时都会发生错误

public void consulta(View v) {
        AdminSQLiteOpenHelper admin = new AdminSQLiteOpenHelper(this, "mimoto",
                null, 1);
        SQLiteDatabase bd = admin.getWritableDatabase();
        String tipor = tiporep.getText().toString();
        //String[] repu = new String[] {tipor};
        Cursor filas = bd.rawQuery("select tipo,precio,fecomrep  from repuestos where tipo=" + tipor
                        + "", null);
        if (filas.moveToLast()) {
            tv01.setText(filas.getString(0));
            tv02.setText(filas.getString(1));
            tv03.setText(filas.getString(2));

        } else
            //Toast.makeText(this, "No existe una persona con dicho dni" + tv3,
                //  Toast.LENGTH_SHORT).show();
        bd.close();
        // Fin ultimo tanqueo
    }

Bateria来自String tipor,一个editext

2 个答案:

答案 0 :(得分:0)

我相信这是因为你附上了变量tipor,其中包含引号中的值bateria。查询应该是

select tipo,precio,fecomrep  from repuestos where tipo="' + tipor
                        + "'", null);

希望这有帮助

答案 1 :(得分:0)

解决方案是

Cursor filas = bd.rawQuery( "select tipo,precio,fecomrep from repuestos where tipo='" + tipor + "'", null);