Reputation: 87
I have the following table and it's working fine:
public static final String BookID = "books_ID";
public static final String Book = "books";
public static final String Author = "Authors";
private static final String BookAuthor_TABLE = bookAuthor_Table";
private static final String[] BookAuthor_AllKeys = new String[] { BookID, Book, Author };
private static final String BookAuthor_CREATE =
"CREATE TABLE " + BookAuthor_TABLE + "("+
BookID + " INTEGER PRIMARY KEY," +
Book + " TEXT," +
Author + " TEXT)";
......
......
public ArrayList<String> getSpecificColumn(String book) {
ArrayList<String> AUTHOR_ARRAYLIST;
AUTHOR_ARRAYLIST = new ArrayList<String>();
db = getWritableDatabase;
String WHERE = Book + "=" + book;
Cursor cursor = db.query(BookAuthor_TAB, BookAuthor_AllKeys, WHERE, null, null, null, null);
while(cursor.moveToNext())
{
String AUTHOR = cursor.getString(cursor.getColumnIndex(Author));
AUTHOR_ARRAYLIST.add(AUTHOR);
}
return AUTHOR_ARRAYLIST;
}
MainActivity:
String book = “Jeff Jordan”
AUTHOR_ARRAY = MySQLITE_DATABASE.getSpecificColumn(book);
System.out.println(AUTHOR_ARRAY);
Why am I getting this error
(1) no such column: Jeff Jordan ?????
I've checked the table, and there was "Jeff Jordan" in the column Author.
What did I do wrong?
Thanks a lot
Upvotes: 1
Views: 4360
Reputation: 152817
String literals should be in 'single quotes'
or else they are taken as identifiers such as column names.
It's even better to use ?
parameters though:
String WHERE = Book + "=?";
Cursor cursor = db.query(BookAuthor_TAB, BookAuthor_AllKeys,
WHERE, new String[] { book },
null, null, null);
Upvotes: 4