Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android WHERE子句的SQLite查询问题_Android_Android Sqlite - Fatal编程技术网

Android WHERE子句的SQLite查询问题

Android WHERE子句的SQLite查询问题,android,android-sqlite,Android,Android Sqlite,大家好,我是android的初学者,在我的应用程序中,我使用SQLite存储下面的详细信息 名字 产品代码 美孚利诺 电子邮件 这里我的问题是WHERE子句,我的意思是我想使用名称和productCode来过滤记录,我在下面编写了代码,但是我遇到了异常,请帮助我一些 主要活动: userDbHelper = new UserDbHelper(getApplicationContext()); sqLiteDatabase = userDbHelper.getReadableDatabase();

大家好,我是android的初学者,在我的应用程序中,我使用SQLite存储下面的详细信息

  • 名字
  • 产品代码
  • 美孚利诺
  • 电子邮件
  • 这里我的问题是WHERE子句,我的意思是我想使用名称和productCode来过滤记录,我在下面编写了代码,但是我遇到了异常,请帮助我一些

    主要活动:

    userDbHelper = new UserDbHelper(getApplicationContext());
    sqLiteDatabase = userDbHelper.getReadableDatabase();
    Cursor cursor = userDbHelper.searchDetails(name,productCode, sqLiteDatabase);
    
    userDbHelper:

    public Cursor searchDetails(String user_name,String productName, SQLiteDatabase db) {
        Cursor cursor = db.rawQuery("select * from " + UserContactDetails.NewUSerInfo.TABLE_NAME + " where" +UserContactDetails.NewUSerInfo.USER_NAME= '" +user_name + "' and UserContactDetails.NewUSerInfo.PRODUCT_CODE ='"+productName+ "'", null);
        return cursor;
    }
    
    日志: 过程:

    com.example.ram_ramadevi.sqllitetutorial, PID: 31620    
    android.database.sqlite.SQLiteException: near "fromuser_infowhere": syntax error (code 1): , while compiling: select * fromuser_infowhere type = ramand name =8008824731
    

    我认为您在连接查询字符串时遗漏了一个空格

     public Cursor searchDetails(String user_name,String productName, SQLiteDatabase db) {
    
            Cursor cursor = db.rawQuery("select * from " + UserContactDetails.NewUSerInfo.TABLE_NAME + " where type = '" +user_name + "' and name = '"+productName+"'", null);
            return cursor;
        } 
    
    试试这个

    public Cursor searchDetails(String user_name,String productName, SQLiteDatabase db) {
    
    Cursor cursor = db.rawQuery("select * from " + UserContactDetails.NewUSerInfo.TABLE_NAME + " where type = '" +user_name + "' and name ='"+productName+ "'", null);
         return cursor;
      } 
    

    请显示日志..在查询中的
    from
    后留出空格。。与此类似,
    “select*from”+UserContactDetai….
    进程:com.example.ram_ramadevi.sqllitettutorial,PID:5390 android.database.sqlite.SQLiteException:无此类列:类型(代码1):,编译时:选择*from user_info,其中type='ram'和name='8008824731'@Krish这不是同一个异常,并向我显示包含列及其数据类型的user_info表。进程:com.example.ram_ramadevi.sqllitettutorial,PID:5390 android.database.sqlite.SQLiteException:无此类列:type(代码1):,编译时:选择*from user\u info where type='ram'和name='8008824731选择*from user\u info where type=ramand name=8008824731此查询肯定会出错,而使用select*from user\u info where type=ram和name='8008824731'@Krish“where”应该是“where”@Krish在where后面添加空格