public HashMap<String, Object> Get_Info(int id){
HashMap<String, Object> map = new HashMap<String, Object>()
String sql = "SELECT * FROM " + TABLENAME +" WHERE ID='" +id +"'"
Cursor result = this.db.rawQuery(sql, null) // 执行查询语句
for (result.moveToFirst() !result.isAfterLast() result.moveToNext()) { // 采用循环的方式检索数据
map.put("A", result.getString(1))
map.put("B", result.getString(2))
map.put("B", result.getInt(3))
}
this.db.close()
return map
}
你说的这种功能,需要花费大量代码来实现的。还不如一个查询一个方法的来做。
下面是示意:
string query(int id, string name, string pwd)
{
string sql = "select * from user"
string where = ""
if (id>0)
where += "id>" + id
if (name != "")
where += "name=" + name
if (pwd!="")
where += "pwd="+pwd
if (where!="")
sql += "where " + where
return sql
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)