DataBase插入麻烦

时间:2013-01-10 07:11:36

标签: android database sqlite android-sqlite

我的应用程序我从textview获取用户名和密码并将其保存在数据库中,当我参与检索这些值时,它显示出某些问题。

广告代码

int id=1;
String id1 = Integer.toString(id);
              passwordTxtValue = passwordTxt.getText().toString();
              passwordTxtValue2 = passwordTxt2.getText().toString();


              if(passwordTxtValue.equals(passwordTxtValue2))
              {

                    try 
                    {
                        db_obj.password_varification(id1, passwordTxtValue);
                        Log.e("Insert Values"," " );
                        PASSWORD_DATA = db_obj.password_records();
                    System.out.println("The value is"+PASSWORD_DATA.size());

                    } 
                    catch (Exception e) 
                    {
                    }
              } 

              else
              {
                  Toast.makeText(getApplicationContext(), "Enter values correctly!!!", Toast.LENGTH_SHORT).show();
                    passwordTxt.setText("");
                    passwordTxt2.setText("");
              }

OpenHelper类是..

static final String password_table = "password_db";
static final String table_id = "table_id";
static final String password = "password";
 @Override
public void onCreate(SQLiteDatabase db) 
{

    db.execSQL("CREATE TABLE "+password_table+"("+table_id+" INTEGER PRIMARY KEY, "+password+" TEXT)");


}
public void password_varification(String id,String paswrd ) 
    {
         Log.d("DB", "Inset_User OK" );
        SQLiteDatabase db=this.getWritableDatabase();
        ContentValues cv=new ContentValues();

        cv.put(table_id, id);
         cv.put(password, paswrd);

         db.insert(password_table, null, cv);


         db.close();
         Log.v("DB", "Inset_User OK" + ""+ id + paswrd); 
    }
 // password Data retrive here
public ArrayList<HashMap<String, String>> password_records() 
{
     SQLiteDatabase db=getReadableDatabase();
     ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

     Cursor cursor=db.rawQuery("SELECT "+table_id+" as _id,  "+password+" from "+password_table,new String [] {});
    //Cursor cursor=db.rawQuery("SELECT "+row+" as _id, "+twitter+" from "+winery_info_2,new String [] {});


         if(cursor!=null)             
         {
             if(cursor.moveToFirst())  // movies first column 
             {
                 do
                 {
                     HashMap<String, String> map = new HashMap<String, String>();

                     String  fnam        = cursor.getString(cursor.getColumnIndex("table_id"));
                     String  lnam        = cursor.getString(cursor.getColumnIndex("password"));

                     map.put (table_id      ,fnam);
                     map.put (password      ,lnam);

                     list.add(map);
                 }
                 while(cursor.moveToNext()); // move to next row

             }
         }

         if (cursor != null && !cursor.isClosed()) 

         {
            cursor.close();
         }

         return list;
   }

显示一些非法状态异常

0 个答案:

没有答案