• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Part of the code is not working in jsp

 
Rashmi Dupati
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

please check the code and give the solution to my problem.

<%@ page import="java.util.*" %>
<jsp:useBean id="dbBean" scope="application" class="burnaby.DbBean"/>
<%
String base = (String) application.getAttribute("base");
%>
<TABLE CELLSPACING="0" CELLPADDING="5" WIDTH="150" BORDER="0">
<TR>
<TD BGCOLOR="F6F6F6">
<FONT FACE="Verdana">Search</FONT>
<FORM>
<INPUT TYPE="HIDDEN" NAME="action" VALUE="search">
<INPUT TYPE="TEXT" NAME="keyword" SIZE="10">
<INPUT type="SUBMIT" VALUE="Go">
</FORM>
</TD>
</TR>
<TR>
<TD BGCOLOR="F6F6F6"><FONT FACE="Verdana">Categories:</FONT></TD>
</TR>
<TR VALIGN="TOP">
<TD BGCOLOR="F6F6F6">

(up to this working fine the below scriplet is not working.it's not displaying categories accessing from database)

<%
Hashtable categories = dbBean.getCategories();
Enumeration categoryIds = categories.keys();
while (categoryIds.hasMoreElements()) {
Object categoryId = categoryIds.nextElement();
out.println("<A HREF=" + base + "?action=browseCatalog&categoryId=" +
categoryId.toString() + ">" +
categories.get(categoryId) +
"</A><BR>");
}
%>
</TD>
</TR>
</TABLE>


and see the DbBean code also

public Hashtable getCategories() {
Hashtable categories = new Hashtable();
try {
Connection connection = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
System.out.println("got connection"+dbUrl);
Statement s = connection.createStatement();
String sql = "SELECT categoryId, category FROM Categories" +
" ";
System.out.println("executing");
ResultSet rs = s.executeQuery(sql);
while (rs.next()) {
categories.put(rs.getString(1), rs.getString(2) );
}
rs.close();
s.close();
connection.close();
}
catch (SQLException e) {}
return categories;
}


thanks in advance
 
Rodrigo Tomita
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rashmi,

Well, if nothing is printed out in your HTML, probably your ResultSet has no rows. I believe you could try to add a print statement to check that.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Santosh Kolekar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rashmi,

you have not post what err you getting. plese post err msg.
Also check whether it works by following change.

Enumeration categoryIds = categories.iterator();


ALL THE BEST
 
Santosh Kolekar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rashmi,

Try it by iterator.

in my previous post i mentioned
Enumeration categoryIds = categories.iterator();
plese replace it as
Iterator categoryIds = categories.iterator();

All The Best
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic