Мне нужна небольшая помощь в решении проблемы с sqlite. Я пытаюсь сохранить данные json, полученные с сервера, и получаю исключение при попытке вставить HTML-код в базу данных sqlite. Вот код, который я Я использую его и исключение:
КОД:
public boolean executeInsert() {
UserDatabaseHelper userDbHelper = new UserDatabaseHelper(context, null, 1);
userDbHelper.initialize(context);
ContentValues values = new ContentValues();
try {
values.put("objectId", objectId);
values.put("objectOid", objectOid);
String jsonData = new String(contentBuffer,"UTF-8");
Log.w("JSONDATA","JSONDATA VALID OR NOT : "+jsonData);
json = new JSONObject(jsonData);
JSONObject jsonObj =(JSONObject) new JSONTokener(jsonData).nextValue();
locale = jsonObj.getString("locale");
Log.w("LOCALE","SHOW LOCALE : "+locale);
contentType = Integer.parseInt(jsonObj.getString("content_type"));
Log.w("CONTENT TYPE","SHOW CONTENT TYPE : "+contentType);
values.put("contentType", contentType);
format = Integer.parseInt(jsonObj.getString("format"));
Log.w("FORMAT","SHOW FORMAT : "+format);
values.put("format", format);
title = jsonObj.getString("title");
Log.w("TITLE","SHOW TITLE : "+title);
values.put("title", title);
content = jsonObj.getString("content");
Log.w("CONTENT","SHOW CONTENT : "+content);
values.put("content", content);
lastUpdate = jsonObj.getString("last_updated");
Log.w("LAST UPDATED","LAST UPDATED : "+lastUpdate);
values.put("dateUpdated", lastUpdate);
collectionId = jsonObj.optInt("collection_id", 0);
values.put("collectionId", collectionId);
cardId = jsonObj.optInt("card_id", 0);
values.put("cardId", cardId);
userDbHelper.executeQuery("content", values);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
Log.w("Error","FUCKKKKKKKKKKKKKK ERROR : "+e);
} catch (JSONException e) {
e.printStackTrace();
Log.w("Error","FUCKKKKKKKKKKKKKK ERROR : "+e);
}
return true;
}
ИСКЛЮЧЕНИЕ:
09-27 08:48:52.279: ERROR/Database(7862): Error inserting content=Welcome to Stampii<br />
09-27 08:48:52.279: ERROR/Database(7862): <br />
09-27 08:48:52.279: ERROR/Database(7862): Your favourite collections synchronised on your computer and your mobile in a new format: stampii Download them with photos, and constantly updated statistics. Swap and play with your friends and enjoy their contents even when you're offline!<br />
09-27 08:48:52.279: ERROR/Database(7862): <br />
09-27 08:48:52.279: ERROR/Database(7862): From theArea in the Kiosk, you'll be able to browse through all tha active collections, and find the one that you like best.<br />
09-27 08:48:52.279: ERROR/Database(7862): <br />
09-27 08:48:52.279: ERROR/Database(7862): Once you've selected the choosed collection, you just have to activate it to start enjoying your. You can make as many collections as you want at the same time.<br />
09-27 08:48:52.279: ERROR/Database(7862): <br />
09-27 08:48:52.279: ERROR/Database(7862): You can purchase yourfrom theStore, via sms or promotional vouchers.<br />
09-27 08:48:52.279: ERROR/Database(7862): <br />
09-27 08:48:52.279: ERROR/Database(7862): Allfollow a similar structure. They're all represented with a portrait with an image and all the data referred to the character that you've got in your.<br />
09-27 08:48:52.279: ERROR/Database(7862): <br />
09-27 08:48:52.279: ERROR/Database(7862): Your collection will be updated for free with the last info every time you select the sincronize button. Yourconstantly updated.<br />
09-27 08:48:52.279: ERROR/Database(7862): <br />
09-27 08:48:52.279: ERROR/Database(7862): Enjoy searching, negotiating and changing your repeated stampii with your friends, use your mobile and the social networks to get the you were looking for. title=Title Tutorial format=2 contentType=1 objectId=1 dateUpdated=2010-03-26 16:56:43
09-27 08:48:52.279: ERROR/Database(7862): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
09-27 08:48:52.279: ERROR/Database(7862): at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
09-27 08:48:52.279: ERROR/Database(7862): at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:55)
09-27 08:48:52.279: ERROR/Database(7862): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1623)
09-27 08:48:52.279: ERROR/Database(7862): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1484)
09-27 08:48:52.279: ERROR/Database(7862): at com.stampii.stampii.comm.rpc.UserDatabaseHelper.execQuery(UserDatabaseHelper.java:252)
09-27 08:48:52.279: ERROR/Database(7862): at com.stampii.stampii.comm.rpc.UserDatabaseHelper.executeQuery(UserDatabaseHelper.java:247)
09-27 08:48:52.279: ERROR/Database(7862): at com.stampii.stampii.comm.rpc.ContentRPCPacket.executeBefore(ContentRPCPacket.java:105)
09-27 08:48:52.279: ERROR/Database(7862): at com.stampii.stampii.user.UserLogin$2$1.run(UserLogin.java:365)
09-27 08:48:52.279: ERROR/Database(7862): at java.lang.Thread.run(Thread.java:1102)
EDIT
Вот моя функция, которую я использую для вставки данных в SQLite:
public boolean executeQuery(String tableName,ContentValues values){
return execQuery(tableName,values);
}
private boolean execQuery(String tableName,ContentValues values){
sqliteDb = instance.getWritableDatabase();
sqliteDb.insert(tableName, null, values);
return true;
}
Я использую этот метод так:
userDbHelper.executeQuery("content", values);//content is the name of my table
//userDBHelper is an instance of my DatabaseHelper class.
И какой тип данных у меня на столе:
- id (целое число)
- objectId (целое число)
- формат (целое)
- contentType (целое число)
- dateUpdated (varchar)
- содержание (текст)
- objectOid (varchar)
Есть идеи, как это исправить, чтобы я мог сохранить HTML-код в sqlite?