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

就是不知道下面哪里出错了
<%!
String   id= " ";
String   admin_name= " ";
String   password= " ";
int   currid=1;
String   sql= " ";
String   sql1= " ";
ResultSet   rsTmp=null;
ResultSet   rsaa=null;
%>
<%
rsTmp=conn.executeQuery( "select   max(id)   as   maxid   from   admin ");
if(rsTmp.next())
currid=rsTmp.getInt( "maxid ")+1;


request.setCharacterEncoding( "GBK ");
admin_name=request.getParameter( "admin_name ");

password=request.getParameter( "password ");
//如果TITLE不为空,则添加记录
if(request.getParameter( "admin_name ")!=null)
{
//执行插入操作
sql= "select   *   from   admin   where   admin_name= "+admin_name;
rsaa=conn.executeQuery(sql);
System.out.println(sql);
    if(rsaa.next()){
    out.println( "该用户已经存在! <a   href=manager_edit.jsp>   重新添加! </a> ! ");}
    else{
sql= "insert   into   admin   values( ' "+currid+ " ', ' "+admin_name+ " ', ' "+password+ " ') ";
System.out.println(sql);
conn.executeUpdate(sql);
//out.println( " <h2> <a   href= "manager.jsp "> 返回 </a> </h2> ");
out.println( "添加成功! <a   href=manager.jsp> 返回! </a> ! ");
        }
}
else
{
}
%>

跟数据库连接没错得     只是重复的管理员数据可以插入   rsaa这个结果集中为空   但是数据库中却是有数据的   请各位大哥帮帮忙

------解决方案--------------------
1. 没有看到你的数据库链接
2. sql= "select * from admin where admin_name= "+admin_name;
=> sql= "select * from admin where admin_name= ' "+admin_name + " ' ";
3. 把System.out.println(sql);中打出来的sql放到数据库中去执行,看结果是否正确