我正在使用sqlite。我已成功创建了数据库和表。我还编写了可以向表中插入新值的代码。我的代码运行完美,但现在我想要实现:例如,如果插入了新值,则显示toast消息,否则在toast或其他地方显示错误消息。这是我的插入表源代码:
public void InsertToPhysicalPersonTable(String FirstName, String LastName,
String FullName, String FatherName) {
try {
ContentValues newValues = new ContentValues();
newValues.put("FirstName", FirstName);
newValues.put("LastName", LastName);
newValues.put("FullName", FullName);
newValues.put("FatherName", FatherName);
db.insert(AddNewPhysicalPerson, null, newValues);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
Toast.makeText(myContext, "Something wrong", Toast.LENGTH_SHORT).show();
}
}
我这样调用了我的函数:
loginDataBaseAdapter.InsertToPhysicalPersonTable("FirstName",
"LastName",
"FullName",
"FatherName"
);
如果有人知道解决方案,请帮助我。 谢谢。