【问题标题】:Android - SQLiteException: near "=": syntax error (code 1)Android - SQLiteException:靠近“=”:语法错误(代码 1)
【发布时间】:2015-10-31 08:25:14
【问题描述】:

我正在尝试使用用户 ID 记录用户表中的 ID 和作业表中的作业名

String select = "SELECT jobname FROM " + TABLE_JOBS+ "where userid =" +myid;

【问题讨论】:

  • 在你的表 TABLE_JOBS 'userid' 是整数类型?
  • "where userid="+myid; 前缺少空格改为使用 " where userid="+myid;

标签: java android sql sqlite android-cursor


【解决方案1】:
"SELECT jobname FROM " + TABLE_JOBS+ "where userid =" +myid;

您需要在标识符(例如表名)和关键字(例如 where)之间使用空格:

"SELECT jobname FROM " + TABLE_JOBS+ " where userid =" +myid;

【讨论】:

    【解决方案2】:

    您在 where 子句之前缺少一个空格,因此它直接附加到表名中,并且您实际上没有 where 子句:

    String select = "SELECT jobname FROM " + TABLE_JOBS+ " where userid =" +myid;
    // whitespace was missing here -----------------------^
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-03
      • 1970-01-01
      • 2018-08-02
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-13
      相关资源
      最近更新 更多