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

  • SEARCH
  • Home
  • 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 4045436
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:25:39+00:00 2026-05-20T13:25:39+00:00

I have a query string that is dynamic. The items I am searching for

  • 0

I have a query string that is dynamic. The items I am searching for in the database are based upon what the user selects in a checkbox on an html form. The user types selects a city name from a drop down list. Then the user can select from 3 different attributes to the city: CountryCode(int), District(String), and Population(int).

I have no problem creating the query. For example if the user selects Tulsa and selects District and Population the queryString SELECT District, Population FROM City WHERE name ='Tulsa' is created no problem. For another example if the user simply selected country code of Tulsa the query string created would be SELECT CountryCode FROM City WHERE name ='Tulsa'.

The problem is parsing the data and displaying it neatly to the screen. I am no database programmer so I am having a tough time. Here is a tidbit of my code so you can see what I’m doing.

The only thing I can do correctly is if the user selects District and Population. Any other selection doesn’t work. I am basically hard coding District and Population. I am not sure how to parse it dynamically. Here is the code. Query string is SELECT District, Population FROM City WHERE name ='Tulsa'. Its the only one I can get to work.

public String getData( String c)
    {

        String query = c;
        ResultSet rs = null;
                StringBuffer back = new StringBuffer();

        try
        {
            rs = st.executeQuery(c);
            ResultSetMetaData rsmd = rs.getMetaData();

            int numColumns = rsmd.getColumnCount();
            back.append( "number of columns is " + numColumns);
                        back.append( "</br>");

            back.append( "<table border=\"10\" >\n" );
                        while(rs.next())
                        {
                            if(rsmd.getColumnTypeName(1).equals("CHAR"))
                                back.append("<tr><td>" + rsmd.getColumnName(1) + "</td>" + "<td>" + rs.getString(1) + "</trd</tr>");

                            if(rsmd.getColumnTypeName(2).equals("INT"))
                                back.append("<tr><td>" + rsmd.getColumnName(2) + "</td>" + "<td>" + Integer.toString(rs.getInt(2)) + "</td></tr>");

            }
            back.append( "</table>" );
        }
        catch( SQLException e )
        {
            back.append( "<h6>something bad is happening</h6>");
            e.printStackTrace();
            return null;
        }
        return new String( back );
    }

I hope you guys understand what I’m asking. Thanks alot for the help!

  • 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-05-20T13:25:40+00:00Added an answer on May 20, 2026 at 1:25 pm

    If all you want to do is output the data, you can just get everything as a String using ResultSet.getString(index) since you know the number of columns from your metadata.

    while(rs.next())
    {
        for (int i = 1; i <= numColumns; i++)
        {
            back.append("<tr><td>" + rsmd.getColumnName(i) +
                        "</td>" + "<td>" + rs.getString(i) + "</trd</tr>");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a showall query string parameter in the url, the parameter is being
I've noticed that a few Wordpress blogs have query statistics present in their footer
I have a query that is dynamically built after looking up a field list
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have a query on my database as such: SELECT * FROM expenses WHERE
I have a query that I'm executing from a .NET application to a SQL
I have a MS Access query ProductDetailsAll that is queried using an ASP.net web
I am trying to convert a Linq query that I have working in Linq
I have a PHP based site with dynamic pages , such as /page.php?ID=1. The

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.