• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Part of the code is not working in jsp

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Run away! Run away! Here, take this tiny ad with you:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic