2012-06-20 161 views
0

它給我的錯誤。如何獲得所有的功能。感謝如何從sqlite檢索數據Android

show.setOnClickListener(new Button.OnClickListener() { 
    public void onClick(View arg0) 
    { 
      String mm = seg.getText().toString(); 
      String mmm =ubs.getText().toString(); 
      String mmmm=area.getText().toString(); 
      String mmmmm= microarea.getText().toString(); 
      String mmmmmm= imovel.getText().toString(); 
           String query = (" SELECT * FROM DOMICIL WHERE " 
       + " SEG ="+ mm 
       + " And UNIDADE ="+mmm 
       + " And AREA ="+mmmm 
       + " And MICROAREA ="+mmmmm 
       + " And IMOVEL ="+ mmmmmm); 
      Cursor c =my.rawQuery(query,null); 
      c.moveToFirst(); 
      while(!c.isAfterLast()) 
      { 
       int id = c.getInt(0); 
       seg.setText(c.getString(1)); 
       ubs.setText(c.getString(2)); 
       area.setText(c.getString(3)); 
       microarea.setText(c.getString(4)); 
       imovel.setText(c.getString(5)); 
       numer_casa.setText(c.getString(6)); 
       cep.setText(c.getString(7)); 
       complemento.setText(c.getString(8)); 
       c.moveToNext(); 
      } 
      c.close(); 
      } 
     }); 
    } 
+2

它給出了哪個錯誤? –

+1

您不應該從未經檢查的用戶輸入構建查詢 –

回答

0

假設你列的文字,嘗試圍繞你的文字中引號查詢..

前。

+ " SEG = '"+ mm + "'" 
+ " And UNIDADE = '"+mmm + "'" 
+ " And AREA = '"+mmmm + "'" 
+ " And MICROAREA = '"+mmmmm + "'" 
+ " And IMOVEL = '"+ mmmmmm + "'"); 
0

if if null,use for Strings; SEG LIKE %'"+mm"'%

0

如果我是你,我可能會做一些像

String query = " SELECT * FROM DOMICIL WHERE " 
       + " SEG = ? " 
       + " And UNIDADE = ?" 
       + " And AREA = ? " 
       + " And MICROAREA = ? " 
       + " And IMOVEL = ? "; 
Cursor c =my.rawQuery(query,new String[]{mm,mmm,mmmm,mmmmm,mmmmmm}); 

我還使用更具描述性的變量名。

相關問題