数据更改的问题

来源:百度知道 编辑:UC知道 时间:2024/05/30 00:20:21
例如,一笔数据,当别人比如将这笔数据删除了,但是我这边因为没有对页面进行刷新,肯定还显示着这笔数据.而我不知道这笔数据被删除了,又对这笔数据进行了一些操作,导致程序报错.我应该怎样做才能让系统避免这种情况.java

you need to do two things:

1. dont really remove the record when deleting the data, just mark it deleted instead.

2. you need to use "optimistic locking" to solve the problem. your problem is officially called "concurrency control" in data access. if you use no framework in your application, you need to handle it by yourself.

briefly, "optimistic locking" is very simple in that, you check the time stamp of the record and see if it's different from what you've got at hand.

在提交时判断当前操作的记录是否还存在就行了。
一般都是在存储过程或事务中判断。

你删除之前判断下当前数据是否存在就可以了啊?