创建表:
sql = "create table member(memberNum int(64) not null primary key, memberName varchar(64) not null,memberLevel INT(5) not null, "
+ "memPhone INT(64) not null, memberSex INT(2), memberBirthday DATE,memberAddres VARCHAR(64), "
+ "memberEffectBegin DATE, memberEffectEnd DATE,bak VARCHAR(64))";
对其进行插入操作是:
@Override
public boolean addMember(Member member) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
String str = null;
synchronized (helper) {
boolean flag = false;
try {
if (isMemberInData(member.memberNum)) {
flag = false;
} else {
ContentValues cv = new ContentValues();
cv.put(tableMemberNum, member.memberNum);
cv.put(tableMemberName, member.memberName);
cv.put(tableMemberLevel, member.memberLevel);
cv.put(tableMemberPhone, member.memberPhone);
cv.put(tableMemberSex, member.memberSex);
str = format.format(member.memberBirthday);
//cv.put(tableMemberBirthday, ember.memberBirthday.toString()); 错误的方法
cv.put(tableMemberBirthday, str);
cv.put(tableMemberAddress, member.memberAddres);
str = format.format(member.memberEffectBegin);
cv.put(tableMemberEffectBegin, str);
str = format.format(member.memberEffectEnd);
cv.put(tableMemberEffectEnd, str);
cv.put(tableMemberBak, member.memberBak);
if (writeDatabase.insert(table, null, cv) == -1) {
flag = false;
} else {
flag = true;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
}
return flag;
}
}
在对其进行插入的过程中需要将date转化为string,这个时候不能直接使用toString方法,需要按照固定的格式进行转化。
同样再查询的时候需要将String类型的转换到Date类型