Caused by: android.database.sqlite.SQLiteException: near "where": syntax error(Sqlite code 1): , while compiling: select * from wenjian where 1=1 and where cehao=1288,(OS error - 2:No such file or directory)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1334)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1268)
<1>上面是数据库语句写错了:select * from wenjian where 1=1 and where cehao=1288
应该只用一个where :select * from wenjian where 1=1 and cehao=1288
Caused by: android.database.sqlite.SQLiteException: unrecognized token: "01端"(Sqlite code 1): , while compiling: select * from wenjian where 1=1 and duanhao=01端,(OS error - 2:No such file or directory) at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37) at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1334) at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1268)
Caused by: android.database.sqlite.SQLiteException: no such column: LOG(Sqlite code 1): , while compiling: select * from wenjian where 1=1 and gongneng=LOG,(OS error - 2:No such file or directory) at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37) at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1334) at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1268)
最后解决:
select * from wenjian where 1=1 and cehao=1288
这里的数据库表字段都是定义为vachar ,但是cehao字段里面都是存储的数字,这里在拼接sql语句时,这样写是可以运行正确的。
但是当字段存储的数据不是数字,而是字符串的话,需要加单引号(英文单引号不区分左右的),语句应该为:
select * from wenjian where 1=1 and cehao=1288 and duanhao=‘01端’
基础语句不会啊……浪费了2个小时。
学习……