如果表是空的,检查存在行时Sqlite kill app?

时间:2013-04-07 00:20:12

标签: android sqlite

只有在我想检查行存在时,我才会面临Sqlite的问题。

如果table为空,则应该杀死应用程序并由android关闭。我试图追踪问题,但我找不到它,我的代码中的问题在哪里?

这是我的Sql类中的行检查存在函数:

 public boolean clExists( String email )
      {

          Cursor cursor = database.rawQuery("select 1 from "+TABLE_client+" where "+cl_email+"="+email, null);
          boolean exists = (cursor.getCount() > 0) ? true : false;
           cursor.close();
          return exists;

      }

这就是我执行代码的地方(jsinfo.getString(“email”))一个电子邮件字符串从Json数组返回而且它不是空的

datasource.open();
if ( datasource.clExists(jsinfo.getString("email")))
{
    Toast.makeText(Login.this, "exists "+jsinfo.getString("email"), Toast.LENGTH_LONG).show();  
}else
{
    Toast.makeText(Login.this, "not exists "+jsinfo.getString("email"), Toast.LENGTH_LONG).show();
}    
datasource.close();

1 个答案:

答案 0 :(得分:1)

您需要在电子邮件之间使用文字

Cursor cursor = database.rawQuery("select 1 from "+TABLE_client
                                 +" where "+cl_email+"='"+email+"'", null);