private
DAO中的util、rs、sql都应该为private。
其中每个具体方法执行增删改查操作前打开数据库连接,操作完成后关闭数据库连接。操作要规范,不然易出错。
nextval
seq_XX.nextval 计数规则:每通过nextval执行一次操作都会有记录号,即使插入的行已经被删除,系统把已经删除的列也计数在内向后计数。不是通过nextval插入的条目不会计数在内,当然可能手动和nextval混合操作时会产生冲突,如违反主键唯一性约束。这些下面都有实验验证:
如:(自动加入的都是new33名字,便于区分,seq_1 设定从33开始每次递增1)
执行完成后查询;
再执行nextval插入:
在数据库中验证:
PS:现在ID到45,如果手动添加ID47,然后执行NEXTVAL插入,观察结果。
手动插入47,commit;
第一次自动插入,在47后添加了46并验证插入成功:
第二次插入操作:报错!想插入47失败:
继续执行第三次操作,成功: