日期:2014-05-18  浏览次数:20628 次

向高手求救~~~~想了一天也没想出来原因
在我的一个insert-info.jsp中有下面代码:运行完后,发现数据竟然被插入了两遍,其中id相邻,怎么想也想不通。为什么啊???怎么改才能插入一遍数据???


<%@   page   language= "java "   import= "java.util.* "   pageEncoding= "gb2312 "%>
<%@   page   import= "java.sql.ResultSet "%>
<%@   page   import= "brjl.model.DSConnUtils "%>
<%@   page   import= "brjl.model.ParamUtils "%>
<%@   page   import= "brjl.model.StringUtils "     %>
<%@   page   import= "brjl.model.MD5_Test "   %>
<%@   page   import= "brjl.model.getMaxId "   %>
<%
String   path   =   request.getContextPath();
String   basePath   =   request.getScheme()+ ":// "+request.getServerName()+ ": "+request.getServerPort()+path+ "/ ";
System.out.println( "*********insert-info.jsp****** ");
%>

<%

ParamUtils   param   =   new   ParamUtils();
String   user_id   =   param.getStringParameter(request,   "user_id ",   " ");
String   pwd   =   param.getStringParameter(request,   "pwd ",   " ");
String   user_name   =   param.getStringParameter(request,   "user_name ",   " ");
String   sex   =   param.getStringParameter(request,   "sex ",   " ");
String   cert_type   =   param.getStringParameter(request,   "cert_type ",   " ");
String   cert_num   =   param.getStringParameter(request,   "cert_num ",   " ");
String   unit   =   param.getStringParameter(request,   "unit ",   " ");
String   duty   =   param.getStringParameter(request,   "duty ",   " ");
String   tel   =   param.getStringParameter(request,   "tel ",   " ");
String   mail   =   param.getStringParameter(request,   "mail ",   " ");

int   type   =   1;
if(cert_type.equals( "身份证 "))
type   =   0;
DSConnUtils   dbc   =   new   DSConnUtils();
StringUtils   str   =   new   StringUtils();
ResultSet   rs   =   null;

                  //取得数据库中最大id号码
String   sql   =   "select   count(*)   from   accuse_user_info ";
sql   =   str.iso2gb(sql);
rs   =   dbc.executeQuery(sql);  
int   id   =   1;
if(rs.next())id=rs.getInt(1)+1;
                   
                  //把数据添加到数据库表中
String   sql2   =   "insert   into   accuse_user_info   values( ' "+id+ " ', ' "+user_id+ " ', ' "+MD5_Test.MD5(pwd)+ " ', ' "+user_name+ " ', ' "+sex+ " ', ' "+type+ " ', ' "+cert_num+ " ', ' "+unit+ " ', ' "+duty+ " ', ' "+tel+ " ', ' "+mail+ " ') ";
sql2   =   str.iso2gb(sql2);
dbc.executeUp