在Android中的数据库中插入值时出现SQLiteException

时间:2013-09-05 09:29:32

标签: android exception sqlite

我正在尝试在数据库中插入各种名称,并且他们正在插入异常一个这样的名称,即; John O'Mahony。以下是我的崩溃日志:

Failure 1 (near "' AS '": syntax error) on 0x302f70 when preparing 'INSERT INTO authors(author_name, book_key) SELECT 'John O'Mahony' AS 'author_name', '0mS5s0RHTlodXqwcbbsHm9Q9D4cmuAaevUL_TEdByhjMp8VQvcvxksF2LoNVf3dM' AS 'book_key''.

E/AndroidRuntime(5442): android.database.sqlite.SQLiteException: near "' AS '": syntax error: INSERT INTO authors(author_name, book_key) SELECT 'John O'Mahony' AS 'author_name', '0mS5s0RHTlodXqwcbbsHm9Q9D4cmuAaevUL_TEdByhjMp8VQvcvxksF2LoNVf3dM' AS 'book_key'
09-05 12:37:32.262: E/AndroidRuntime(5442):     at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1763)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at com.example.elib.database.BookUploader.uploadBookAuthors(BookUploader.java:260)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at com.example.elib.database.BookUploader.uploadBook(BookUploader.java:81)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at com.example.elib.activity.LibraryActivity.setData(LibraryActivity.java:671)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at com.example.elib.http.CommonAsyncTask.onPostExecute(CommonAsyncTask.java:198)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at com.example.elib.http.CommonAsyncTask.onPostExecute(CommonAsyncTask.java:1)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at android.os.AsyncTask.finish(AsyncTask.java:417)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at android.os.AsyncTask.access$300(AsyncTask.java:127)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at android.os.Looper.loop(Looper.java:123)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at android.app.ActivityThread.main(ActivityThread.java:3683)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at java.lang.reflect.Method.invokeNative(Native Method)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at java.lang.reflect.Method.invoke(Method.java:507)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-05 12:37:32.262: E/AndroidRuntime(5442):     at dalvik.system.NativeStart.main(Native Method)

这是我的创建声明:

CREATE_ELIB_AUTHORS_TABLE = "CREATE TABLE IF NOT EXISTS " +
        TABLE_AUTHORS + " (" +
        "author_id integer primary key autoincrement,"+
        "author_name text," +
        "book_key text"+
        " );";

请告诉我是否有办法解决这个问题?

谢谢。

1 个答案:

答案 0 :(得分:0)

尝试

author_name为'John O'Mahony'。