在android中选择查询?

时间:2013-02-17 17:53:56

标签: android android-sqlite

public Cursor getsomething()
  {
      this.open();
      Cursor c = database.rawQuery("SELECT content_id FROM " +
              DatabaseHandler.Table_Name2 +
              " where  playlist_id==100813", null);
 if (c != null ) {
  if  (c.moveToFirst()) {
        do {
        String path = c.getString(c.getColumnIndex("content_id"));
          MainActivity.t1.append("\n");
         MainActivity.t1.append(path);
        }while (c.moveToNext());
             } 
       }    
        this.close();
      return null;
  }

我使用上面的代码来获取值,但它显示了来自content_id列的所有值。我做错了什么?

this.open();
        ContentValues values2 = new ContentValues();
        String csvFilename = "/mnt/sdcard/playlist.csv";
        CSVReader csvReader = new CSVReader(new FileReader(csvFilename));
        String Rowst[] = null;
        while((Rowst = csvReader.readNext()) != null) {
               st1 = Rowst[0];
               st2= Rowst[1];
               st3= Rowst[2];
               st4= Rowst[3];
               st5= Rowst[4];
               st6 = Rowst[5];
               st7 = Rowst[6];
               st8 = Rowst[7];
               st9 = Rowst[8];
               st10 = Rowst[9];
               st11 = Rowst[10];
               st12 = Rowst[11];
               st13 = Rowst[12];
               st14 = Rowst[13];
               st15 = Rowst[14];
               st16 = Rowst[15];
               st17 = Rowst[16];
               st18 = Rowst[17];
               st19 = Rowst[18];
               values2.put(DatabaseHandler.play1,st1);
               values2.put(DatabaseHandler.play2,st2);
               values2.put(DatabaseHandler.play3,st3);
               values2.put(DatabaseHandler.play4,st4);
               values2.put(DatabaseHandler.play5,st5);
               values2.put(DatabaseHandler.play6,st6);
               values2.put(DatabaseHandler.play7,st7);
               values2.put(DatabaseHandler.play8,st8);
               values2.put(DatabaseHandler.play9,st9);
               values2.put(DatabaseHandler.play10,st10);
               values2.put(DatabaseHandler.play11,st11);
               values2.put(DatabaseHandler.play12,st12);
               values2.put(DatabaseHandler.play13,st13);
               values2.put(DatabaseHandler.play14,st14);
               values2.put(DatabaseHandler.play15,st15);
               values2.put(DatabaseHandler.play16,st16);
               values2.put(DatabaseHandler.play17,st17);
               values2.put(DatabaseHandler.play18,st18);
               values2.put(DatabaseHandler.play19,st19);
           database.insert(DatabaseHandler.Table_Name2, null, values2);

        }
        csvReader.close(); 
        this.close();

这是我在此表中插入数据的代码,我正在尝试读取sdcard上的csv文件并将其数据输入到表中我做错了我已发布此内容如果有帮助

1 个答案:

答案 0 :(得分:1)

public Cursor getsomething()
{
 this.open();
 Cursor c = db.query(DatabaseHandler.Table_Name2, null, "playlist_id=100813", null, null, null, null);

   if (c.getCount() > 0)
    {
     if  (c.moveToFirst())
     {
       do {
              String path = c.getString(c.getColumnIndex("content_id"));
              MainActivity.t1.append("\n");
              MainActivity.t1.append(path);

          }while (c.moveToNext());
     } 
   }    
    this.close();
    return null;
 }