Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9014403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:29:55+00:00 2026-06-16T03:29:55+00:00

The problem that I am having is that I am to create a servlet

  • 0

The problem that I am having is that I am to create a servlet that will get data from three tables (SQL) and print them out in a html table.

The structure of the tables are as follows:

blog_comments:

row id (auto increments), 
blogger id, 
entry_tstamp, 
t_stamp, 
comment, 
author_id, 

blog_entries:

row id(auto increments), 
blogger_id, 
timestamp, 
entry, 

blogger_info:

row id(auto increments), 
blogger_id, 
name, 
email address, 
image, 
password, 

The blog entries are the orignal post and the blog_comments are related to that post. I’m trying to create a table that will show the blogger details followed by the post (from blog_entries) in the first row and in the second row and below, the related comments to that blog.

I am trying to use a while statment (shown below). I had to use a while statement to initally get the inital blog posts and blogger ID and the second while to display comments related to that.

I am having some difficulty as it goes throught the second while loop, it cancels the first while loop (after one increment) and then dumps off the the contents of the second while loop.

Does anyone know if there is a better way of implementing this? Should I be using a comparative loop? And I’m sure that my coding is wrong. Can anyone tell me where I am going wrong?

Thank you.

CODE:

        try {
            Class.forName("org.sqlite.JDBC");
            con = DriverManager.getConnection("jdbc:sqlite:E:/My Documents/NetBeansProjects/co2509blog.sqlite");
            stmt = con.createStatement();
            //String temp = "SELECT entry, name, email, image, comment from blog_comments C, blog_entries E, blogger_info I where E.blogger_id = I.blogger_id  AND I.blogger_id = C.author_id ORDER BY E.timestamp";
            //String temp = "SELECT entry, name, email, image from blog_entries E, blogger_info I where E.blogger_id = I.blogger_id ORDER BY E.timestamp";
            //String temp = "SELECT entry, name, email, image, comment from blogger_info I JOIN blog_entries E ON I.blogger_id = E.blogger_id JOIN blog_comments C ON I.blogger_id = C.author_id WHERE  E.timestamp = C.entry_tstamp ORDER BY E.timestamp";
            String query = "SELECT name, image, email, entry FROM blogger_info I, blog_entries E WHERE I.blogger_id = E.blogger_id ORDER BY E.timestamp";
            String query2 = "SELECT name, image, email, comment FROM blogger_info I, blog_entries E, blog_comments C WHERE I.blogger_id = C.author_id AND E.timestamp = C.entry_tstamp ORDER BY E.timestamp";
            rs = stmt.executeQuery(query);


            //rs2 = stmt.executeQuery(secondQuery);
            // displaying records
            int rowCount = 0;
            int rowCount2 = 0;

            out.println("<P ALIGN='center'><TABLE BORDER=5>");
            ResultSetMetaData rsmetadata = rs.getMetaData();
            int columnCount = rsmetadata.getColumnCount();
            // table header
            out.println("<TR>");
            for (int i = 0; i < columnCount; i++) {
                out.println("<TH>" + rsmetadata.getColumnLabel(i + 1) + "</TH>");
            }
            out.println("</TR>");
            {
                while (rs.next()) {
                    rowCount++;
                    out.println("<TR>");
                    for (int i = 0; i < columnCount; i++) {
                        out.println("<TD>" + rs.getString(i + 1) + "</TD>");
                    }
                    rowCount2++;
                    rs2 = stmt.executeQuery(query2);
                    ResultSetMetaData rsmetadata2 = rs2.getMetaData();
                    int columnCount2 = rsmetadata2.getColumnCount();

                    rsmetadata2 = rs2.getMetaData();
                    out.println("</TR>");
                    while (rs2.next()) {
                        rowCount2++;
                        out.println("<TR>");
                        for (int j = 0; j < columnCount2; j++) {
                            out.println("<TD>" + rs2.getString(j + 1) + "</TD>");
                        }

                    }

                }
                out.println("</TR>");
            }
            out.println("</TABLE></P>");

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:29:57+00:00Added an answer on June 16, 2026 at 3:29 am

    The following line reuses the statement of the first query:

    rs2 = stmt.executeQuery(query2);
    

    As a side effect, the first result set (rs) is closed.

    To fix it, you need to create a separate statement for the inner query:

    stmt2 = con.createStatement();
    
    ..
    
    rs2 = stmt2.executeQuery(query2);
    

    Yet, it would be even more efficient if you could merge the two queries into a single one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create this effect: http://www.thecssninja.com/demo/css_tree/ the problem I'm having is that the
I'm having a problem trying to create a Javascript function that checks all the
the problem that im having is this that i am able to create a
I am trying to create a login form. The problem that I am having
The problem i'm having is that i've created a web service, and a windows
All, The problem I am having is that I created a ListView and set
I'm having the weird problem that after having javascript inject some dom-elements the css-rules
I am having problem that when i am trying to submit the form by
I've been thinking/searching for an equivalent of the problem that I am having below,
HI Guys, Here I am having problem that How can I post an image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.