Android数据库:预检代码

时间:2012-09-22 10:31:23

标签: android sqlite

我是Android新手,我正在制作我的第一款Android应用。在那,我正在创建一个数据库。在此应用程序中,第一次启动应用程序时,我要求用户输入新的密码并在mynewscreen中确认密码。用户下次启动应用程序时,会要求用户输入现有密码并检查数据库中的密码。

但是在代码中,checkDataBase()

附近有错误

我的代码:

SQLiteDatabase sampleDB =  this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);
          Cursor c = sampleDB.rawQuery("SELECT Password FROM " +
                  "password" +
                  " where Username = 'clicklock'", null);

任何人都可以帮助游标c语句中的错误吗?

 public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        logm("App started");

        String chreturn=Make_db();
        Toast.makeText(getApplicationContext(),chreturn,Toast.LENGTH_LONG).show();

        checkDataBase();       

}

 public String Make_db()
    {
   String errormsg = "";
   SQLiteDatabase sampleDB =  this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);
   try {
        sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
                PASSWORD +
                " (Username VARCHAR, Password VARCHAR);");

        sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +            PHOTO + " (photoname VARCHAR, photopath VARCHAR,id INTEGER PRIMARY KEY);");
           msg ="DatabaseCreated";
       } catch (SQLiteException se ) {
        Log.e(getClass().getSimpleName(), "Could not create or Open the database");
        msg ="Not Done Error With Database";
       }
 return msg;

   }
   public  String checkDataBase() {

    try
    {
        SQLiteDatabase sampleDB =  this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);
      Cursor c = sampleDB.rawQuery("SELECT Password FROM " +
              "password" +
              " where Username = 'clicklock'", null);

      String password_db = c.getString(c.getColumnIndex("password"));
        if(password_db=="")
        {

            Intent i = new Intent(CameraLaunch.this, MyNewScreen.class);                
            startActivity(i);               
        }
        else if(password_db=="123123")
        {               
            Intent i = new Intent(CameraLaunch.this, MyNewScreen.class);                
            startActivity(i);       
        }


      return "working";
    }
     catch (SQLiteException se ) {
         Log.e(getClass().getSimpleName(), "Could not create or Open the database");
         Make_db();
         return "Could not create or Open the database";
     }        
}

0 个答案:

没有答案