Monday, November 17, 2008

Java References.*

Hello Friends,

I was trying to generate unordered lists from database through java code in JSP. I am facing difficulties to generate subcategories in
    list.

    I have a table with Menu Items :

    code:
      
    cat_id | parent_id | title
    -------------------------
    1 | 0 | Solutions
    2 | 0 | Products
    3 | 1 | Web
    4 | 1 | Development
    5 | 2 | Softies
    6 | 2 | PHP Book
    -------------------------  


    I want to list get the out put in the form as below :
    code:
     
    Solutions
      Web
      Development
    Products
      Softies 
      PHP Book  


    What i have written is :

    code:
     public String generateMenuHTML(String id) throws SQLException {
      String html, cId, pId;
      pdb = new Pdb();
      rset = pdb.executeQuery("select ID,PARENT_ID,TITLE,URL,SORT,ICON from menu");
      
      html = "
      ";
       
        while(rset.next())
        {
        cId = rset.getString("id");
        System.out.println(cId);
        pId =rset.getString("PARENT_ID");
        html = html + "
    • " + rset.getString("title") + "";
        if (pId.equalsIgnoreCase("1"))
        {
        System.out.println(pId);
        html = html + generateMenuHTML(cId);
        }
        html = html + "
    • ";
         
         
        }  
        rset.close();
        html = html + "
    ";
      return html;
     }
       


    Could you please help me where i am wrong.. how should i join the tables? any idea? Could you please help me how to retrieve sub categories and get the output in :








    Please help me if you can.. Thanks a lot!

    Rgds,
    Sutanuj Majumder.


No comments: