【发布时间】:2013-12-20 05:36:53
【问题描述】:
我正在开发 android 应用程序。实际上,在我的应用程序中,我从之前存储的 sqlite 数据库中获取数据。但是我的 db 列之一包含带有撇号的字符串。当我传递查询时,当传递带有撇号的字符串时,它会显示错误。
下面是我的代码:
String fest = "Guru Rabindranath's Birthday";
querythefest(fest);
public void querythefest(String festname) {
DBAdapter dbAdapter = DBAdapter.getDBAdapterInstance(this);
try {
dbAdapter.createDataBase();
} catch (IOException e) {
Log.i("unable to create database", e.getMessage());
}
dbAdapter.openDataBase();
query2 = "Select desc from List where name='"+ festname + "'";
System.out.println("que " + query2);
arr1 = new ArrayList<ArrayList<String>>();
arr1 = dbAdapter.selectRecordsFromDBList(query2, null);
dbAdapter.close();
}
请帮我解决这个问题。
【问题讨论】:
-
你应该使用这个:String[] festss =new String [] {"New Year","Guru Rabindranath's Birthday"};
-
您的部分问题是您没有使用准备好的语句(您可能对 SQL 注入持开放态度);使用 one 可以解决问题,因为撇号本质上会自动转义。
标签: android