我从API获取数据,然后将该数据插入SQLite数据库。但是,当我插入数据时,存在一些问题。我无法找到这个问题。 我从API获取了正确的数据。没问题。唯一的问题是将数据插入数据库。
我的Json Data Formate是:
{ “SKU”: “T_010”, “PRODUCT_ID”: “7”, “名称”: “footaball”, “thumbnail_image”: “http://www.keyss.in/pos/magento/media/catalog/product/no_selection”, “描述”:NULL, “SHORT_DESCRIPTION”: null,“weight”:“0.0000”,“created_at”:“2013-01-15 07:00:36”,“updated_at”:“2013-01-15 07:00:36”,“price”:“13.0000 “,”special_price“:null,”tax_class_id“:”1“,”cat_id“:[”4“,”15“],”cat_name“:{”4“:”Mobile& Accessories“,”15“: “体育健身”}},
我的主要课程
我的ProductDbHandler类 Link to My database class
Getter和Setter课程 Link to the Getter & Setter Class
我的Logcat显示了这个:
02-05 12:31:39.601: I/Database(274): sqlite returned: error code = 1, msg = table tbProductDetails has no column named cat_id
02-05 12:31:39.621: E/Database(274): Error inserting cat_id=["5"] price=10.0 updated_at=null weight=1.0 product_id=1 tax_class_id=0 description=324354 thumbnail_image=http://www.keyss.in/pos/magento/media/catalog/product/no_selection name=assdfg created_at=2013-01-15 06:19:59 sku=T_001 special_price=12.0 cat_name={"5":"Cameras"}
02-05 12:31:39.621: E/Database(274): android.database.sqlite.SQLiteException: table tbProductDetails has no column named cat_id: , while compiling: INSERT INTO tbProductDetails(cat_id, price, updated_at, weight, product_id, tax_class_id, description, thumbnail_image, name, created_at, sku, special_price, cat_name) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:36)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1536)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410)
02-05 12:31:39.621: E/Database(274): at database.in.ProductDbHandler.addProducts(ProductDbHandler.java:64)
02-05 12:31:39.621: E/Database(274): at com.hellovx100.in.ClerkLogin.getItemsOfDept(ClerkLogin.java:110)
02-05 12:31:39.621: E/Database(274): at com.hellovx100.in.ClerkLogin.onCreate(ClerkLogin.java:92)
02-05 12:31:39.621: E/Database(274): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-05 12:31:39.621: E/Database(274): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-05 12:31:39.621: E/Database(274): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-05 12:31:39.621: E/Database(274): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-05 12:31:39.621: E/Database(274): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-05 12:31:39.621: E/Database(274): at android.os.Handler.dispatchMessage(Handler.java:99)
02-05 12:31:39.621: E/Database(274): at android.os.Looper.loop(Looper.java:123)
02-05 12:31:39.621: E/Database(274): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-05 12:31:39.621: E/Database(274): at java.lang.reflect.Method.invokeNative(Native Method)
02-05 12:31:39.621: E/Database(274): at java.lang.reflect.Method.invoke(Method.java:521)
02-05 12:31:39.621: E/Database(274): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-05 12:31:39.621: E/Database(274): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-05 12:31:39.621: E/Database(274): at dalvik.system.NativeStart.main(Native Method)
我在做错的地方请指导我。
任何帮助都是适当的。
编辑:我认为问题在于josn data formate,我得到“cat_id”:[“4”,“15”],“cat_name”:{“4”:“Mobile&amp; Accessories” ,“15”:“Sports Fitness”}},我们如何在json中解析它,因为它就像数组中的数组一样。 logcat也在错误 02-05 12:31:39.601:I / Database(274):sqlite返回:错误代码= 1,msg =表tbProductDetails没有名为cat_id的列如何处理这类问题
答案 0 :(得分:0)
我认为这是你的问题,你错过了一个空间。
而不是:
database.in.DatabaseAndTableNames.PRODUCT_DISCRIPTION_COLUMN+"TEXT,"
试
database.in.DatabaseAndTableNames.PRODUCT_DISCRIPTION_COLUMN+" TEXT,"
答案 1 :(得分:0)
在此发布您的创建声明.. 验证并确保添加cat_id列和特定数据类型。
答案 2 :(得分:-2)
02-05 11:13:09.993:I / Database(287):sqlite返回:错误代码= 1,msg =没有这样的表:tbProductDetails
首先创建表然后插入数据..