Android ListView详解(5)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-25 11:34 点击:次
import com.lamp.domain.Person;
public class PersonService {
private DataBaseOpenHelper dbHelper = null;
private SQLiteDatabase sqLiteDatabase = null;
public PersonService(Context context) {
dbHelper = new DataBaseOpenHelper(context);
sqLiteDatabase = dbHelper.getWritableDatabase();
}
public void save(Person person){
String sql = "insert into person(name,age) values (?,?)";
sqLiteDatabase.execSQL(sql, new Object[]{person.getName(),person.getAge()});
}
//指定删除
public void delete(Integer personid){
String sql = "delete from person where personid=?";
sqLiteDatabase.execSQL(sql,new Object[]{personid});
}
//批量删除
public void deletePersons(Integer... ids){
StringBuilder sb = new StringBuilder();
if(ids.length > 0){
for (int i = 0; i < ids.length; i++) {
sb.append('?').append(',');
}
sb.deleteCharAt(sb.length()-1);
String sql = "delete from person where personid in ("+ sb +")";
sqLiteDatabase.execSQL(sql,(Object[])ids);
}
}
//更新数据
public void update(Person person){
String sql = "update person set name=?,age=? where personid=?";
sqLiteDatabase.execSQL(sql, new Object[]{person.getName(),person.getAge(),person.getPersonid()});
}
//得到全部的结果集
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>