ormlite增、删、改、查

package com.ormlite;



import java.sql.SQLException;
import java.util.List;
import java.util.Map;


import com.data.AddMer;
import com.j256.ormlite.dao.Dao;


public class AddMerDB {


private Dao dao;


public AddMerDB(Dao dao) {
this.dao = dao;
}

//添加
public void insert(AddMer object) {
try {
dao.create(object);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}

//修改
public void update(AddMer object) {
try {
dao.update(object);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

//删除
public void delete(AddMer object) {
try {
dao.delete(object);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

//查询
public AddMer find() {
AddMer tab = null;
try {
List object = dao.queryForAll();
if(object!=null&&object.size()>0){
tab=object.get(0);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return tab;
}

public List find(Map map) {

List object =null;
try {

//模糊查询

if (map != null && !map.isEmpty()) {
String key = "";
String value = "";
Set> set = map.entrySet();
for (Entry en : set) {
key = en.getKey();
value = en.getValue();
}
object = dao.queryBuilder().where().like(key, "%" + value + "%")
.query();
// QueryBuilder qb=dao.queryBuilder();
// qb.where().like(key, "%"+value+"%");
// PreparedQuery pq = qb.prepare();
// list=dao.query(pq);
}

//List object =dao.queryForFieldValues(map);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return object;
}
}

你可能感兴趣的:(android小技巧)