English 中文(简体)
对比结果与变量
原标题:compare resultset result with a variable
  • 时间:2010-10-03 11:33:51
  •  标签:
  • java
  • jsp
  • jdbc

I am having some difficulties in java while comparing between a variable and the next resultset. In my case, I want : if the temp variable = rs.next() then temp ="" else the rs.next() value should be displayed.

这是因为我多次走到国名现场,所以我要再次找回。

我的法典

while(rs.next()){

%>
        <tr>
            <td width="238">
                <%temp=rs.getString("TNAME");%> 
                <%=temp%> </td>
            <td><%=rs.getString("ID")%></td>
                    <%
                           if (rs.next().equals(temp){ 
            temp="";
            }


}

rs.close();

%> 
最佳回答

ResultSet#next(><>><>>>, not a /code>, 其中载有你之后的栏值。 但现在,你真的不想把 cur子转移到那里下一行。 当你回头 lo时,你有效地ski了一行。

您需要改变逻辑:将目前<><>>>现成><代码> > 姓名/代码>与previously 相容,只在情况不同时显示。 然后将目前上载 > 姓名作为变量加以储存,以便在下一个版本中加以比较。 The a kickoff example based on JSTL/EL and a fictive List<Item> which is used as ${items} in the scope:

<table>
    <c:forEach items="${items}" var="item">
        <tr>
            <td><c:if test="${item.name != previousName}">${item.name}</c:if></td>
        </tr>
        <c:set var="previousName" value="${item.name}" />
    </c:forEach>
</table>

如果你坚持使用,你只需要将其翻译成老式的scriptlets。 以上逻辑应当足以自我解释。

问题回答

我认为你有两个问题:

  1. you re iterating through your loop using rs.next() but inadvertently jumping again by your second rs.next() call.
  2. you re comparing your temp string to rs.next() and not the particular field you re interested in.




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签