如何解决SQLiteLog(3507):( 1)在“=”附近:android中的语法错误sqlite。我的数据库可以正常运行错误。 logcat显示第1行中的语法错误。
public void openAndQueryDatabase()
{
try
{
db = openOrCreateDatabase( "mydatabase.db", SQLiteDatabase.CREATE_IF_NECESSARY , null );
Cursor cursor = db.rawQuery("select * from "+ table + "where name='"+ name + "'", null); //line 1
int count = cursor.getColumnCount();
if (cursor != null )
{
if (cursor.moveToFirst())
{
do
{
for (int i =0 ; i< count; i++)
{
String data = cursor.getString(i);
details.add(data);
}
}
while (cursor.moveToNext());
}
}
}
catch (SQLiteException se )
{
Log.e(getClass().getSimpleName(), "Error in the code");
}
finally
{
db.close();
}
}
答案 0 :(得分:2)
您的表名与where
关键字之间需要一个空格:
Cursor cursor = db.rawQuery("select * from "+ table + " where name='"+ name + "'", null);
还要考虑使用?
绑定args用于文字,例如
Cursor cursor = db.rawQuery("select * from "+ table + " where name=?", new String[] { name });