判断用户是否存在 若存在 则在用户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();}
}
}
%>
<%
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();}
}
}
%>
建表的时候 给id 声明 auto_increment
得到序列的下一个值或当前值,用下面语句
select your_sequence.nextval from dual;--获得序列your_sequence的下一个值
虽不连号,但还是可以惟一的,这样不要数据库也行。