0

每次运行应用程序时都会出现错误

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,一个编辑文本

4

2 回答 2

0

我相信这是因为您已将变量tipor 包含在引号中,其中包含值bateria。查询应该是

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

希望这可以帮助

于 2013-05-10T16:08:57.737 回答
0

解决方案是

Cursor filas = bd.rawQuery( "select tipo,precio,fecomrep from repuestos where tipo='" + tipor + "'", null);
于 2013-05-22T05:56:17.290 回答