我从webservice获得了价值。我的一些价值观带有单引号。像这个样本的sqlite不支持单引号。所以我用双引号替换它们。然后我从db中检索值,我无法解析该值。我解析器异常不正常。谁能告诉我怎么做?
这是我的代码将单引号替换为双引号
stockservicevalue=stockservicevalue.replaceAll("'", "\"");
这是我从db
中检索的值String sql = "SELECT * FROM MyQuest;";
日志:
03-28 19:02:36.309: WARN/System.err(344): org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 50437: not well-formed (invalid token)
03-28 19:02:36.321: WARN/System.err(344): at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:492)
03-28 19:02:36.330: WARN/System.err(344): at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:477)
03-28 19:02:36.340: WARN/System.err(344): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:317)
03-28 19:02:36.380: WARN/System.err(344): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:273)
03-28 19:02:36.389: WARN/System.err(344): at com.inquest.SaxPortfolioDocument.getEventsFromAnXML(SaxPortfolioDocument.java:13)
03-28 19:02:36.411: WARN/System.err(344): at com.inquest.PortfolioActivity$PortFolioTask.doInBackground(PortfolioActivity.java:171)
03-28 19:02:36.420: WARN/System.err(344): at com.inquest.PortfolioActivity$PortFolioTask.doInBackground(PortfolioActivity.java:1)
03-28 19:02:36.430: WARN/System.err(344): at android.os.AsyncTask$2.call(AsyncTask.java:185)
03-28 19:02:36.430: WARN/System.err(344): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
03-28 19:02:36.440: WARN/System.err(344): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
03-28 19:02:36.479: WARN/System.err(344): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
03-28 19:02:36.500: WARN/System.err(344): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
03-28 19:02:36.510: WARN/System.err(344): at java.lang.Thread.run(Thread.java:1096)
03-28 19:02:36.840: WARN/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@46dfec78
由于
答案 0 :(得分:9)
stockservicevalue=stockservicevalue.replaceAll("'", "\''");
答案 1 :(得分:1)
我们可以使用android DatabaseUtils类。
stockservicevalue = DatabaseUtils.sqlEscapeString(stockservicevalue);
答案 2 :(得分:0)
我认为正确的格式是stockservicevalue=stockservicevalue.replaceAll("\'", "\"");
答案 3 :(得分:-1)
如何使用SQLite Java插入单引号。它对我有用。
String str = "'Hello";
str = str.replace("'","\\'");