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

[] - 新手请问

2012-01-11 
[求助] - 新手请教%@pagecontentType text/htmlcharsetgb2312 language java import java.sql.

[求助] - 新手请教
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "%>
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN "   "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 号码判断 </title>
</head>
<%
Class.forName( "com.sybase.jdbc.SybDriver ").newInstance();
String   url   = "   jdbc:sybase:Tds:133.40.102.254:5000/info1000 ";
Properties   SysProps   =   System.getProperties();
SysProps.put( "user ", "info1000 ");
SysProps.put( "password ", "suntek ");
Connection   conn=   DriverManager.getConnection(url,SysProps);
String   action   =   request.getParameter( "action ");
String   telNum   =   request.getParameter( "tel_num ");
ResultSet   rs   =null;
if(action==null)action= " ";
if(telNum==null)telNum= " ";
if(action.equals( "seach ")){
Statement   stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String   sql= "select   *   from   remarkphs   where   tel_num   =   ' "+telNum+ " ' ";
String   name= " ";
rs=stmt.executeQuery(sql);
while(rs.next())   {
name=   rs.getString(1);
out.println( "有此号码 ");
}
rs.close();
stmt.close();
conn.close();
}
%>
<body>
<form   name   = "bb "   action= "?action=seach "   method= "post "   >   请输入号码: <input   type= "text "   class= "box "   size=18   name= "tel_num ">    
            <td> <input   type= "submit "   name= "test "   value= "判断号码 "> </td>

</form>
</body>
</html>        


此页实现功能为检索输入号码是否为表内数据
现本程序现可判断输入号码同在表内的数据

急需加入一个判断输入号码不在表内数据的程序
请指教
谢谢


[解决办法]
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* "%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 号码判断 </title>
</head>
<%
Class.forName( "com.sybase.jdbc.SybDriver ").newInstance();
String url = " jdbc:sybase:Tds:133.40.102.254:5000/info1000 ";
Properties SysProps = System.getProperties();
SysProps.put( "user ", "info1000 ");
SysProps.put( "password ", "suntek ");
Connection conn= DriverManager.getConnection(url,SysProps);
String action = request.getParameter( "action ");
String telNum = request.getParameter( "tel_num ");
ResultSet rs =null;
if(action==null)action= " ";
if(telNum==null)telNum= " ";
if(action.equals( "seach ")){
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);


String sql= "select * from remarkphs where tel_num = ' "+telNum+ " ' ";
String name= " ";
rs=stmt.executeQuery(sql);
if(rs.size()==0){
out.println(telNum);
out.println( "无此号码 ");
}
rs.close();
stmt.close();
conn.close();
}
%>
<body>
<form name = "bb " action= "?action=seach " method= "post " > 请输入号码: <input type= "text " class= "box " size=18 name= "tel_num ">  
<td> <input type= "submit " name= "test " value= "判断号码 "> </td>

</form>
</body>
</html>

[解决办法]
嘻嘻.我来教你。
try
{
........前面省略...

rs=stmt.executeQuery(sql);
if(!rs.next())
throw new Exception( "无数据 ");//


else
{
for(int i=0;i <100;i++)//100是你看想它出来多少条数据.你也可以写50。随你自己写

{
............

if(!rs.next())
break;
}

}
}

}
catch(Exception )
{
String msr=e.getMessage();
out.println(msr);
}


[解决办法]
上面多了一个}这样的括号

热点排行