判断用户是否存在 若存在 则在用户id后添加流水号(以后依次加一) 这段代码怎么写 
<%
public class JDBC {
Connection conn=null; 
PrepareStatement psm = null;
ResultSet rs = null;public Connection getConnection(){
try
{
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    String url = "jdbc:mysql://localhost:3306/mydb";
con = DriverManager.getConnection(url,"root","000000");
psm = con.prepareStatement("select * from users where username=?");
psm.setString(1,name);
rs = psm.executeQuery();
if(rs!=null){ //用户名已存在
  
在id后添加流水号代码
}
else{//用户名可用
   
获取软件注册页面的注册信息
}    
catch(Exception e){
  response.sendRedirect("register.jsp");
}
 finally
 {
     if(rs!=null){
     try{ rs.close();}catch(Exception e){e.printStackTrace();}
   }
     if(psm!=null){
     try{ psm.close();}catch(Exception e){e.printStackTrace();}
   }  
   if(con!=null){
     try{ con.close();}catch(Exception e){e.printStackTrace();}
   } 
}
%>

解决方案 »

  1.   

    oracle数据库的话加个触发器就可以了,不知道mysql是怎么做的。帮lz顶了!
      

  2.   

    自动增长类型设置.
    建表的时候 给id 声明 auto_increment
      

  3.   

    mysq有个自动增长类型、auto_increment  在建表的时候声明下就好、然后每次创建都会自动加1~
      

  4.   

    1.可以使用自动增长的表实现;2.也可以自己设计一个sequence表。每次去读取sequence,然后加1;3.如果使用oracle,建议使用oracle的dual表。
       得到序列的下一个值或当前值,用下面语句
          select your_sequence.nextval from dual;--获得序列your_sequence的下一个值
      

  5.   

    用Java里面的日期生成一个序号呗,
    虽不连号,但还是可以惟一的,这样不要数据库也行。