关于JDBC(please help!)

happy2program 2003-03-20 11:47:20
squery="select UName from UInfo where UName="+"'"+v.get(0)+"'"+"";
sta=con.createStatement();
res=sta.executeQuery(squery);
我想有下面的流程
if(记录集为0)
{}
else if(记录集为1)
{}
else
{}
请问记录集的个数如何获得,我对jsp是个新手,谢谢!
...全文
46 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
happy2program 2003-03-20
  • 打赏
  • 举报
回复
这种方法我知道,但我的流程不允许这样做!
squery="select UName from UInfo where UName="+"'"+v.get(0)+"'"+"";
sta=con.createStatement();
res=sta.executeQuery(squery);
我想有下面的流程
if(记录集为0)
{
<jsp:forward page="error.jsp">
<jsp:param name="username1" value="<%=v.get(0)%>" />
</jsp:forward>
}
else if(记录集为1)
{}
else
{
while(res.next()){%>
<%=res.getString("UName")%>
<%}

}

sikuan 2003-03-20
  • 打赏
  • 举报
回复
squery1="select count(*) from UInfo where UName="+"'"+v.get(0)+"'"+"";
sta1=con.createStatement();
res1=sta.executeQuery(squery);
int sqlcount=0
if(res1.next()){
sqlcount=res1.getInt(1);
}
res1.close();
if(sqlcount==0)
{}
else if(sqlcount==1)
{}
else
{}
blackisle 2003-03-20
  • 打赏
  • 举报
回复
我用weblogic7,sql2000
这段代码能够通过
TOMCAT下不知道了
还有如结果集只是查询个数的话可以不将指针指向BOF
int a ;
try
{
a = Integer.valueOf("123").intValue() ;
}
catch(Exception e)
{
a = 0 ;
}
应该是好用的阿
happy2program 2003-03-20
  • 打赏
  • 举报
回复
我是在 tomcat下运行的,为什么他不支持res.beforeFirst();
呀,说javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]Unsupported method: ResultSet.beforeFirst

还有他也不支持 String到Int的转换,我以包括了<%@ page import="java.lang.*"%>不解说
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
..\work\localhost\INFOBASE\_0002fjsp_0002fnum_0002fSetProjectPerson_0002ejspSetProjectPerson_jsp_5.java:92: Method parseInt(java.lang.String) not found in class jsp.num._0002fjsp_0002fnum_0002fSetProjectPerson_0002ejspSetProjectPerson_jsp_5.
shark7823 2003-03-20
  • 打赏
  • 举报
回复
gz
blackisle 2003-03-20
  • 打赏
  • 举报
回复
int i = 0 ;
while(res.next())
{
i++ ;
}
res.beforeFirst();
switch(i)
{
case 0:
...
break ;
case 1:
...
break ;
}
================================================================================ Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================================================ Apache Tomcat Version 8.0.15 Release Notes ========= CONTENTS: ========= * Dependency Changes * API Stability * Bundled APIs * Web application reloading and static fields in shared libraries * Security manager URLs * Symlinking static resources * Viewing the Tomcat Change Log * Cryptographic software notice * When all else fails =================== Dependency Changes: =================== Tomcat 8.0 is designed to run on Java SE 7 and later. ============== API Stability: ============== The public interfaces for the following classes are fixed and will not be changed at all during the remaining lifetime of the 8.x series: - All classes in the javax namespace The public interfaces for the following classes may be added to in order to resolve bugs and/or add new features. No existing interface method will be removed or changed although it may be deprecated. - org.apache.catalina.* (excluding sub-packages) Note: As Tomcat 8 matures, the above list will be added to. The list is not c

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧