数据不显示在sqlite数据库中

时间:2016-02-17 11:17:39

标签: android database sqlite

我在我的android项目中创建了一个SQlite数据库表,我可以插入行并从该表中检索值,但是如果我尝试从Sqlite软件加载数据库表它不显示我的表,请给出一个谢谢你。

我尝试过:

//creating Database
private static final String TABLE_BUYMAGISSUE= "buymagazine";//buy issues table
private static final String MAGCAT_ID= "magid";
private static final String MAGSELECTBOOK_ID= "issueid";
private static final String MAGBUY_ID= "androidissuebuyid";
private static final String MAGBUYIMG_URL= "coverimage_path";
private static final String MAGBUY_TITLE= "title";
private static final String MAGBUYPDF_URL= "uploadfile_path";

String CREATE_BUYMAGTABLE ="CREATE TABLE " + TABLE_BUYMAGISSUE + "("+ KEY_ID + "  INTEGER PRIMARY KEY," + MAGCAT_ID + " TEXT," + MAGSELECTBOOK_ID + " TEXT," + MAGBUY_ID + " TEXT," + MAGBUYIMG_URL + " TEXT," + MAGBUY_TITLE + " TEXT," +MAGBUYPDF_URL +" TEXT" + ")";
  db.execSQL(CREATE_BUYMAGTABLE);

  //Inserting  Values
  dbs.insertBuyedMagIssueDetails(strMagBookId, select_bookID, buyIssue_ID, strBuyImg, strBuyTitle, strBuyPDF);

  //DBclass
  public  void insertBuyedMagIssueDetails(String strMagBookId,String select_bookID,String strBuyID,String strBuyImg,String strBuyTitle,String strBuyPDF) {
    // TODO Auto-generated method stub
    //bookname=bookname.trim();
    try
    {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();

        values.put(MAGCAT_ID, strMagBookId);
        values.put(MAGSELECTBOOK_ID, select_bookID);
        values.put(MAGBUY_ID, strBuyID);
        values.put(MAGBUYIMG_URL, strBuyImg);
        values.put(MAGBUY_TITLE, strBuyTitle);
        values.put(MAGBUYPDF_URL, strBuyPDF);

        db.insert(TABLE_BUYMAGISSUE, null, values);

        Log.d("inserted success",TABLE_BUYMAGISSUE);
        db.close(); // Closing database connection
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}

 // Retrieving values
 ArrayList<List<String>> arrbookcatgory = new ArrayList<List<String>>();
 arrbookcatgory = dbs.getBuyMagIssueName("buymagazine");

                String[] arrCatId = new String[arrbookcatgory.size()];
                String[] arrSelectBook = new String[arrbookcatgory.size()];
                String[] arrBuyId = new String[arrbookcatgory.size()];
                String[] arrBuyImage = new String[arrbookcatgory.size()];
                String[] arrBuyTitle = new String[arrbookcatgory.size()];
                String[] arrBuyPdf = new String[arrbookcatgory.size()];

                int length = arrbookcatgory.size();
                for (int i = 0; i < length; i++) {
                    arrCatId[i] = arrbookcatgory.get(i).get(0);
                    arrSelectBook[i] = arrbookcatgory.get(i).get(1);
                    arrBuyId[i] = arrbookcatgory.get(i).get(2);
                    arrBuyImage[i] = arrbookcatgory.get(i).get(3);
                    arrBuyTitle[i] = arrbookcatgory.get(i).get(4);
                    arrBuyPdf[i] = arrbookcatgory.get(i).get(5);
                }

            }catch (Exception e)
            {
                e.printStackTrace();
            }



        //DB class
           public ArrayList<List<String>> getBuyMagIssueName(String tableName)
{
    Cursor c = null;
    ArrayList<List<String>> Category=new ArrayList<List<String>>();

    // TODO Auto-generated method stub
    try{
        String mypath = DB_PATH + DATABASE_NAME;
        myDataBase = SQLiteDatabase.openDatabase(mypath, null, SQLiteDatabase.OPEN_READWRITE);
        SQLiteDatabase db =myDataBase;// getReadableDatabase();
        //String query="SELECT * FROM  subcategory   where catid=?" ,   new String [] {catId};
        //String query="SELECT * FROM subcategory WHERE catid ="+ catId+"";
        c = db.rawQuery("SELECT * FROM "+tableName+" ",null);
        if (c.getCount()>0)
        {
            if(c.moveToFirst()) // rent
            {
                do
                {
                    ArrayList<String> listRent = new ArrayList<String>() ;
                    String Catid=c.getString(0);
                    String selectIssueid=c.getString(1);
                    String buyId=c.getString(2);
                    String buyImage=c.getString(3);
                    String buyTitle=c.getString(4);
                    String buyPdf=c.getString(5);


                    listRent.add(Catid);
                    listRent.add(selectIssueid);
                    listRent.add(buyId);
                    listRent.add(buyImage);
                    listRent.add(buyTitle);
                    listRent.add(buyPdf);

                    Category.add(listRent);
                }
                while(c.moveToNext());
            }
        }
        return Category;
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    finally{
        if (c!=null)
            c.close();

    }
    return null;
}

1 个答案:

答案 0 :(得分:0)

如果您希望在完成时保存值,则需要处于事务(并且COMMIT)。

SQLiteDatabase db = this.getWritableDatabase();
 db.beginTransaction()

...插入,更新,删除等

if (ok) {
db.setTransactionSucessful();
}
db.endTransaction();
db.close();

抱歉&#39;回合格式化,因为我已经回答了任何问题。