首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

向高手求救~想了一天也没想出来原因,该怎么处理

2012-01-02 
向高手求救~~~~想了一天也没想出来原因在我的一个insert-info.jsp中有下面代码:运行完后,发现数据竟然被插

向高手求救~~~~想了一天也没想出来原因
在我的一个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.executeUpdate(sql2);  
rs.close();
rs   =   null;
dbc.close();


  %>

  <jsp:forward   page= "ly-01.jsp "     />



[解决办法]
//取得数据库中最大id号码
String sql = "select count(*) from accuse_user_info ";
如果是取得数据库中最大id号码的化  这条sql 是错的

select max(id) from accuse_user_info才是取得最大id号.
[解决办法]
<%@ page import= "brjl.model.DSConnUtils%>
把导入的这个类贴出 来看看呢

[解决办法]
lz把数据库中accuse_user_info表id字段设置为自动增长即可。
这句sql写的不对:String sql = "select count(*) from accuse_user_info ";

热点排行