插入的Andr​​oid SQLite数据库的html code

问题描述:

我需要,我have.I'm试图挽救JSON数据,我从服务器获取一个SQLite问题一点点的帮助,我得到一个异常试图插入HTML code到sqlite的database.Here是在code,我usig它和异常:

I need a little help with an sqlite issue that I have.I'm trying to save json data which i get from the server and I get an exception trying to insert html code into the sqlite database.Here is the code I am usig for it and the exception :

code:

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)

修改

下面是关于哪些我使用SQLite中插入数据我的功能:

Here is my function about which I am using for inserting data in 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;
}

我使用这个方法是这样的:

I am using this method like this :

userDbHelper.executeQuery("content", values);//content is the name of my table
//userDBHelper is an instance of my DatabaseHelper class.

和什么样的数据类型我有我的表:

And what type of data I have on my table :


  1. ID(整数)

  2. 对象ID(整数)

  3. 格式(整数)

  4. 的contentType(整数)

  5. dateUpdated(VARCHAR)

  6. 内容(文本)

  7. objectOid(VARCHAR)

任何想法如何解决这个问题,所以我可以保存HTML code SQLite中?

Any ideas how to fix that so I can save the html code in sqlite?

尽量简化您的code,直到你得到它的工作。首先,更换行:

Try to simplify your code until you get it working. Firstly, replace the line:

content = jsonObj.getString("content");

随着行:

content = "somethingsimple";

如果这样的作品,那么你知道这件事情有关内容字符串。

If that works, then you know it's something about the content string.

你知道该列的最大尺寸是多少?

Do you know the max size of that column?