In this case, ResultSet object is created, but it doesn't contain any rows. Try in this way,
 
 
Statement stmt=myConn.createStatement();
ResultSet myResultSet=stmt.executeQuery("select nama from user where id='"+login+"' and pass='"+pass+"' ");
 
if (myResultSet.next)
{
   
 String nama =  myResultSet.getString("nama");
%>
<tr>
  <td><%= nama %></td>
</tr>
<% 
 while ( myResultSet.next() ) {
 nama= myResultSet.getString("nama");
 }
 
%>
<tr>
  <td><%= nama %></td>
  </tr>
  // memulai session
  <%
  session.setAttribute ("user", nama);
  %>
  <jsp:forward page="browsevcd.jsp" />
  
<%
 
}
else
{
%>
<jsp:include page="header.htm"  flush="true"/>
 <table>
 <tr><td colspan="2">Tabel</td></tr>
 <%
         out.println("You are not logged in");
  %>
 </table>
 <jsp:include page="footer.htm" flush="true"/>
       <%
 
}
stmt.close();
myConn.close();
%>
 
 
-Seshubaba       
-----Original Message-----
From: Isak Rickyanto [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 26, 2001 3:05 AM
To: [EMAIL PROTECTED]
Subject: If resultset is null

Hello all ....
 
I want to ask about this code...
 
This code get resultset from database,,, but if it is null (the null result set) doesn't run the
code in the else section
 
I can't understand what is the problem ... If I use sql tag or not... those have same result...
 
the code in else don't run.... 
 
:< .. Please help me..... :<
 
the code :
 
Statement stmt=myConn.createStatement();
ResultSet myResultSet=stmt.executeQuery("select nama from user where id='"+login+"' and pass='"+pass+"' ");
 
if (myResultSet != null)
{
 while ( myResultSet.next() ) {
String nama= myResultSet.getString("nama");
%> 
<tr>
  <td><%= nama %></td>
  </tr>
  // memulai session
  <%
  session.setAttribute ("user", nama);
  %>
  <jsp:forward page="browsevcd.jsp" />
  
<%
  }
}
else
if (myResultSet == null)
{
         %>
       <jsp:include page="header.htm"  flush="true"/>
      <table>
        <tr><td colspan="2">Tabel</td></tr>
      <%
      out.println("You are not logged in");
      %>
       </table>
 <jsp:include page="footer.htm" flush="true"/>
       <%
 
}
 
stmt.close();
myConn.close();
%>

Reply via email to