我一直试图在数据库中插入一条记录,但即使我以前做过,它也不能在 Android 中工作。这是我第一次在 ORMLite 中处理多个表。
这就是我想要做的:将数据从 XML 存储到模型中,然后尝试从模型中插入数据。
使用的数据库:SQLite ORM:ORMLite
活动类
TbDriverInfoBO tbDriverInfoBO = new TbDriverInfoBO();
Document doc = XMLfunctions.XMLfromString(strResult);
NodeList nodes = doc.getElementsByTagName("root");
Element root = (Element) nodes.item(0);
jabongModel.setLoginId(XMLfunctions.getValue(root, "UserId"));
jabongModel.setPassword(XMLfunctions.getValue(root, "UserPwd"));
jabongModel.setDrsno(XMLfunctions.getValue(root, "DRSNo"));
jabongModel.setBrancode(XMLfunctions.getValue(root, "BranchCode"));
jabongModel.setLoginDate(XMLfunctions.getValue(root, "LoginDate"));
//clsDriverInfo obj = new clsDriverInfo(loginId, pswd, drsno,
/*tbDriverInfoBO.setColUserId(jabongModel.getLoginId());
tbDriverInfoBO.setColPwd(jabongModel.getPassword());
tbDriverInfoBO.setColDrs(jabongModel.getDrsno());
tbDriverInfoBO.setColBranch(jabongModel.getBrancode());*/
tbDriverInfoBO.fillBo(jabongModel);
dbHelperTbDriverInfo.addData(tbDriverInfoBO);
BO类:
public class TbDriverInfoBO {
@DatabaseField(generatedId = true)
int id;
@DatabaseField
String colUserId;
...
// getters and setters
public TbDriverInfoBO(String colUserId, String colPwd, String colDrs, String colBranch)
{
this.colBranch = colBranch;
this.colDrs = colDrs;
this.colPwd = colPwd;
this.colUserId = colUserId;
}
public TbDriverInfoBO() {
// TODO Auto-generated constructor stub
}
public void fillBo(JabongModel jabongModel)
{
this.colBranch = jabongModel.getBrancode();
this.colDrs = jabongModel.getDrsno();
this.colPwd = jabongModel.getPassword();
this.colUserId = jabongModel.getLoginId();
//this.id = jabongModel.getId();
}
}
DBHelperClass
public int addData(TbDriverInfoBO tbDriverInfoBO) {
int i=0;
RuntimeExceptionDao<TbDriverInfoBO, String> dao = getTbDriverInfoDaO();
try{
i = dao.create(tbDriverInfoBO);
}
catch (Exception e) {
e.getStackTrace();// TODO: handle exception
}
return i;
}
我无法弄清楚我哪里出错了。有人请帮忙!!!
这是堆栈跟踪(获得日志猫):
01-28 15:43:46.251: D/dalvikvm(368): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
01-28 15:43:46.251: D/dalvikvm(368): GC_FOR_MALLOC freed 8148 objects / 498080 bytes in 72ms
01-28 15:43:49.514: D/dalvikvm(368): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
01-28 15:43:50.790: D/dalvikvm(368): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
01-28 15:43:50.900: I/Database(368): sqlite returned: error code = 1, msg = no such table: tbdriverinfobo
01-28 15:43:58.681: D/dalvikvm(368): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)
01-28 15:44:01.956: D/dalvikvm(368): threadid=1: still suspended after undo (sc=1 dc=1 s=Y)