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

rs.next 问题???
我要实现的功能是,先从数据库里查询accout   phone   这2个字段,
要是
String   accout=request.getParameter( "accout ");
String   phone=request.getParameter( "phone ");
接收的数据和查询的数据相同,
就执行
out.print( " <script> alert( '帐号或电话已被人使用,请重新填写 ');history.back(); </script> ");
要是不相同   就执行
sql= "insert   into   base_info(accout,phone,esn,imsi,sid,nid)values( ' "+accout+ " ', ' "+phone+ " ', ' "+esn+ " ', ' "+imsi+ " ', ' "+sid+ " ', ' "+nid+ " ') ";
statement.executeUpdate(sql);  
要怎样写呢???

<%  
ResultSet   rs;
String   accout=request.getParameter( "accout ");
String   phone=request.getParameter( "phone ");
String   esn=request.getParameter( "esn ");
String   imsi=request.getParameter( "imsi ");
String   sid=request.getParameter( "sid ");
String   nid=request.getParameter( "nid ");
%>
<%@   include   file= "conn.jsp "   %>
<%  
String   sql= "select   *   from   base_info   where   accout= ' "+accout+ " '   and   phone= ' "+phone+ " ' ";
rs=statement.executeQuery(sql);
if   (rs.next())
{
out.print( " <script> alert( '帐号或电话已被人使用,请重新填写 ');history.back(); </script> ");
}
else
{
sql= "insert   into   base_info(accout,phone,esn,imsi,sid,nid)values( ' "+accout+ " ', ' "+phone+ " ', ' "+esn+ " ', ' "+imsi+ " ', ' "+sid+ " ', ' "+nid+ " ') ";
statement.executeUpdate(sql);  
}
rs.close();
statement.close()   ;
connection.close();
%>

------解决方案--------------------
rs.close();
statement.close() ;
connection.close();
最好写成
if(rs!=null)
rs.close();
if(statement!=null)
statement.close() ;
if(connection!=null)
connection.close();

------解决方案--------------------
String accout1=request.getParameter( "accout ");
String phone1=request.getParameter( "phone ");
String accout= " ",phone= " ";

String sql= "select * from base_info ";
rs=statement.executeQuery(sql);
while(rs.next()){
accout=rs.getString( "accout ");
phone=rs.getString( "phone ");
if(accout.equals(accout1) || phone.equals(phone1)){
out.print( " <script> alert( '帐号或电话已被人使用,请重新填写 ');history.back(); </script> ");
}
}

------解决方案--------------------
二次查询