generating menu from DB in jsp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • waa

    generating menu from DB in jsp

    Hi,
    I want to generate a side menu from a database list and sort it
    alphabetically.
    I am not please with what i get which is NOT alphabetical.
    Below are my codes:
    --------BEAN-------------------------------------
    public static void loadAllCategori es() throws ProductActivity Exception
    {
    if (allLoaded) return;
    Category cat = null;
    try
    {
    dbConn = ConnectionFacto ry.getConnectio n();
    if(dbConn == null)
    {
    System.out.prin tln("Couldnt get DB Connection");
    throw new CustomerActivit yException();
    }
    PreparedStateme nt pstmt
    =dbConn.prepare Statement(sql_b undle.getString ("findAllCats") );
    ResultSet rs = pstmt.executeQu ery();
    while (rs.next())
    {findCategory(r s.getString("CA TEGORY_NAME")); }
    rs.close();
    pstmt.close();
    }
    catch (Exception e)
    {
    System.out.prin tln("Error during loadAllCategori es");
    e.printStackTra ce();
    throw new ProductActivity Exception();
    }
    finally
    {
    try { dbConn.close(); }
    catch (Exception e) { System.out.prin tln("Error during
    releaseConnecti on");}
    }
    allLoaded = true;
    }
    -------------------------JSP------------------------------------------------
    <%
    Category.loadAl lCategories();
    Iterator it = Category.getCat egories().itera tor();
    while (it.hasNext())
    {
    String catName = (String) it.next();
    %>
    <a class="menuleft " href="Category. jsp?category=<% = catName %>">
    <%= catName %>
    </a>
    <br>
    <%
    }
    %>
    ------------------DB------------------------------------
    SELECT CATEGORY_NAME FROM CATEGORY ORDER BY CATEGORY_NAME ASC;
    The reult I get from this in MySQL is satisfactory. But JSP displays
    it differently.

    Anyone there with an idea.Thanks.
Working...