没有这样的列:嘿(代码 1 SQLITE_ERROR[1]):,在编译时:SELECT ID FROM ALLWORKHOURS WHERE NOTEMEMOS = hey

no such column: hey (code 1 SQLITE_ERROR[1]): , while compiling: SELECT ID FROM ALLWORKHOURS WHERE NOTEMEMOS = hey

登录猫:

no such column: hey (code 1 SQLITE_ERROR[1]): , while compiling: SELECT ID FROM ALLWORKHOURS WHERE NOTEMEMOS = hey

代码:

    102) public String getID(String note){
    103)      SQLiteDatabase db = this.getWritableDatabase();
    104)      String  query = ("SELECT " + COL_0 + " FROM " + TABLE_NAME + " WHERE " + COL_5 + " = " + note);
    105)      db.rawQuery(query,null);
    106)      return query;
    107) }

我的数据库中确实有一个列名嘿 Database Picture

您的查询应如下所示

SELECT ID FROM ALLWORKHOURS WHERE NOTEMEMOS = 'hey'

如果有帮助请告诉我

连接参数 note 的方式创建了这个 sql 语句:

SELECT ID FROM ALLWORKHOURS WHERE NOTEMEMOS = hey

所以 hey 被认为是列标识符而不是字符串文字,因为它没有包含在单引号内。
您可以这样做:

String  query = "SELECT " + COL_0 + " FROM " + TABLE_NAME + " WHERE " + COL_5 + " = '" + note + "'";

它会起作用。
但是推荐的方法是像这样将参数作为字符串数组传递:

String  query = "SELECT " + COL_0 + " FROM " + TABLE_NAME + " WHERE " + COL_5 + " = ?";
Cursor cursor = db.rawQuery(query, new String[] {note});
return cursor;

这样你就不用担心单引号了,因为这是由 rawQuery() 处理的。
我猜你想要 return Cursor 对象而不是 sql 查询字符串,对吗?

你的术语很混乱。

hey是一个值,NOTEMEMOS是一列。

您需要引用该值,嘿,让 SQL 编译器知道它是一个字符串值,而不是您要比较的列。

String  query = ("SELECT " + COL_0 + " FROM " + TABLE_NAME + " WHERE " + COL_5 + " = '" + note + "'");

请注意,您最好使用参数化查询,因为使用原始值是不安全的(参见 SQL 注入)。

String  query = ("SELECT " + COL_0 + " FROM " + TABLE_NAME + " WHERE " + COL_5 + " = ?"); // That's right, quotes aren't needed for a parameterized query.
String result = "";
Cursor cursor = db.rawQuery(query,new String[] {note} );
if (cursor.moveToFirst()) {
    result = cursor.getString(cursor.getColumnIndex(COL_0));
}
cursor.close();
return result;