gpt4 book ai didi

java - SQL 结果集处理

转载 作者:行者123 更新时间:2023-12-01 15:15:51 25 4
gpt4 key购买 nike

谁能帮我解决这个 SQL。我“应该”有一个记录,事实上,我知道我有一个记录,但代码正在落入 catch 表达式。

好的...我修改了代码并得到了相同的结果。陷入异常

<%
String sqlpminfo = "select ea.PreferredName, ea.LastName, ea.AreaCityCode, ea.PhoneNo, eemail.EmployeeEmailAddress from Program p join ProgramXXXEmployeeRole pxxx on pxxx.ProgramID = p.ProgramID and pxxx.RoleCode=799 join EmployeeAdmin ea on ea.XXXEmployeeCode = pxxx.XXXEmployeeCode join EmployeeEmail eemail on eemail.XXXEmployeeCode = pxxx.XXXEmployeeCode where p.ProgramID=" + formFields.getValue("programID");

try {
log.info(sqlpminfo);
log.info("programID: " + formFields.getValue("programID"));
QueryWrap pmwrap = new QueryWrap();
ResultSet pmrt = pmwrap.executeQueryWithException(sqlpminfo);
if (pmrt == null || pmrt.equals(""))
{ pmrt.close();


}
else
{
int i = 0;
while ( pmrt.next() )
{
String pmFname = pmrt.getString(1);
String pmLname = pmrt.getString(2);
String pmAreacode = pmrt.getString(3);
String pmPhone = pmrt.getString(4);
String pmemail = pmrt.getString(5);
log.info ("PM Contact: " + pmrt.getString(1) + " " + pmrt.getString(2) );

%>
Name: <%=pmFname%> <%=pmLname%> <br/>
Email: <a href="mailto:<%=pmemail%>"><%=pmemail%></a><br/>

Phone: (<%=pmAreacode%>)
<%if (pmPhone.length() == 7) {%><%=pmPhone.substring(0, 3)%>-<%=pmPhone.substring(3, 7)%> <%} else {%><%=pmPhone%><%} %>
<br/><br/>
<%

i++;
} //end of while

pmrt.close();
if(i == 0)
{
%>
Contact Information is not available. Please email <br/>
<%
}
} //end if if

} catch (Exception ee) {
%>
log.error("caught exception in PMcontactinfo: " + e);



<% }%>

最佳答案

pmrt.last() :将光标移动到结果集中的最后一行。
pmrt.getRow() :返回行号。如果您有 10 个匹配结果,这将在您的场景中给出 10 个。
pmrt.beforeFirst() :将再次将光标设置到结果集的第一行之前。您现在可以使用 pmrt.next() 获取结果集中的第一行。

你能把你得到的异常粘贴到这里吗?

关于java - SQL 结果集处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32845383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com