2016-09-21 42 views
-3

我正在開發一個android應用程序,使用eclipse jsp和mysql。在這我需要在正確的標籤下顯示在android佈局中的特定表的所有行(例如:我有一個名爲演示的表在mysql中與字段id名稱和地址,我想顯示在android中的演示表的所有行在表格格式(ID,名稱,地址))。我怎樣才能用jsp和android來做到這一點?有人請幫助我。如何在Android中顯示來自mysql表的內容?

回答

0

使用數組列表和大豆類來獲取和顯示數據u要顯示

public ArrayList<SigninBean> getUser() { 
      //  onCreate(getWritableDatabase()); 
      SigninBean sBean = new SigninBean(); 
      ArrayList<SigninBean> arList = new ArrayList<>(); 
      // String selectQuery = "SELECT * FROM " + TABLE_Name + " WHERE " 
      //   + KEY_DATE + " = ?"; 
      // String[] args={tag}; 
      SQLiteDatabase db = this.getReadableDatabase(); 
      String query = "SELECT * FROM " + TABLE; 
      Cursor cursor = db.rawQuery(query, null); 


      if (cursor.moveToFirst()) { 

       while (cursor.isAfterLast() == false) { 

        String d = cursor.getString(cursor.getColumnIndex(COLUMN_signin_date)); 
        String photo = cursor.getString(cursor.getColumnIndex(COLUMN_signin_photo)); 
        String gender = cursor.getString(cursor.getColumnIndex(COLUMN_signin_gender)); 
        String time = cursor.getString(cursor.getColumnIndex(COLUMN_signin_time)); 
        String accurate = cursor.getString(cursor.getColumnIndex(COLUMN_Signin_accurate)); 
        String name = cursor.getString(cursor.getColumnIndex(COLUMN_signin_name)); 
        String city = cursor.getString(cursor.getColumnIndex(COLUMN_signin_city)); 
        String country = cursor.getString(cursor.getColumnIndex(COLUMN_signin_country)); 

        sBean.setName(name); 
        sBean.setPhoto(photo); 
        sBean.setTime(time); 
        sBean.setGender(gender); 
        sBean.setCity(city); 
        sBean.setCountry(country); 
        sBean.setDate(d); 
        sBean.setAccurate(accurate); 
        Log.e("User values r=========>", "" + d + " " + name + " " + city + " " + country + " " + d); 

        cursor.moveToNext(); 
        arList.add(sBean); 
       } 
      } 
+0

我的意思是在本地服務器檢索從MySQL數據庫中的數據,而不是從源碼。感謝您的回覆。 – Deepu

+0

是Json形式嗎? –

+0

不是json form.Is只能以json的形式嗎? – Deepu

相關問題