weixin_42467806
2011-07-05 15:02jsp请求插入数据库 出现重复数据
先简要说下代码
index.jsp 嵌入如下代码
[code="java"]<% String info = DataBaseUtil.getPlayerInfo(userId); %>
[/code]
DataBaseUtil.java
[code="java"]
public class DataBaseUtil {
private static JdbcTemplate jdbcTemplate = (JdbcTemplate) ApplicationContext.getBean("jdbcTemplate");
public static void getPlayerInfo(String userId)
{
if(hasExist(userId))//查找user,看是否存在相应userId的信息
{
dosomething();
}else
{
insertUser();
dosomething();
}
} [/code]
说明:
user有个自增的主键,另有个user_id,应该是唯一的但我没有加唯一索引
有时会插入user_id重复的记录
加入同步块后问题依旧
[code="java"]
synchronized(userId)
{
if(hasExist(userId))//查找数据库,看是否存在相应userId的信息
{
dosomething();
}else
{
insertUser();
dosomething();
}
} [/code]
- 点赞
- 回答
- 收藏
- 复制链接分享
9条回答
为你推荐
- spring mvc 事务失效问题
- spring
- 0个回答
- 想让session不超时,对于我这个问题怎么处理?
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- jsp请求插入数据库 出现重复数据
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- 请教关于在struts2中传递参数,怎么做,谢谢
- struts
- 0个回答
- xmlhttprequest可以跨域访问吗?
- ajax
- javascript
- 0个回答
换一换