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 6986601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:49:48+00:00 2026-05-27T18:49:48+00:00

I am trying to use JSP on server-side to perform a variable number of

  • 0

I am trying to use JSP on server-side to perform a variable number of queries and output the result of all of them as a single block of JSON data for an ExtJS line chart.

The reason the number of queries is variable is because each one represent a different series (a different line) on the line chart, and the number of series is different depending on the line chart that the user selects.

I am using hibernate and my persistence class returns each query data as a: List<Map<String, Object>> (each Map represents one row).

There will always be at least one series (one line on the graph, one query to execute), so the way I was thinking of setting this up is as follows:

1) Have the initial query run and get the first series

2) Run another query to check for any other series that should be on the graph

3) For each “other” series found in the second query run a query that gets the data for that series (same number of rows) and then merge that data into the first List<Map<String, Object>> that was returned in #1 as another column. The query is set-up to order it properly it just needs to be merged at the same index level.

4) Output that List as JSON.

My problem is with #3, I am not sure how to go about the merging the data.

Here’s what I have so far:

GenericSelectCommand graphData = new GenericSelectCommand(graphDataQuery);
GenericSelectCommand backSeriesData = new GenericSelectCommand(backSeriesQuery);

List<Map<String, Object>> graphDataList;
List<Map<String, Object>> backSeriesList;

try
{
    Persistor myPersistor = new Persistor();

    // 1) GET THE INITIAL LINE CHART SERIES
    myPersistor.executeTransact(graphData);
    graphDataList = graphData.getRows();

    // 2) LOOK FOR ANY ADDITIONAL SERIES THAT SHOULD BE ON THE LINE CHART
    myPersistor.executeTransact(backSeriesData);
    backSeriesList = backSeriesData.getRows();

    // 3) FOR EACH ADDITIONAL SERIES FOUND, RUN A QUERY AND APPEND THE DATA TO THE INITIAL LINE CHART SERIES (graphDataList)
    for (int i = 0; i < backSeriesList.size(); i++)
    {
        Map<String, Object> backSeriesBean = backSeriesList.get(i);

        // THIS QUERY RETURNS ONE COLUMN OF INT VALUES (THE LINE CHART DATA) WITH THE EXACT SAME NUMBER OF ROWS AS THE INITIAL LINE CHART SERIES (graphDataList)
        String backDataQuery = "exec runQuery 'getBackData', '" + backSeriesBean.get("series_id") + "'";

        GenericSelectCommand backData = new GenericSelectCommand(backDataQuery);
        myPersistor.executeTransact(backData);
        List<Map<String, Object>> backDataList = backData.getRows();

        // FOR EACH RECORD IN THE BACK DATA (Map<String, Object>)
        for (int i = 0; i < backDataList.size(); i++)
        {
            Map<String, Object> backDataBean = backDataList.get(i);
            // HOW DO I ADD IT TO THE RECORD AT THE SAME INDEX LEVEL IN graphDataList (List<Map<String, Object>>)
        }

    }


}
catch (Throwable e)
{
    System.err.println("Error: ");
    System.err.println(e.getCause());
}
finally
{
    myPersistor.closeSession();
}

// 4) RETURN THE DATA AS JSON NOW THAT IT IS MERGED
for (int i = 0; i < graphDataList.size(); i++)
{
    Map<String, Object> graphDataBean = graphDataList.get(i);
    out.println(/*JSON FORMAT + graphDataBean.get('data') + JSON FORMAT*/)
}

SOLUTION:

GenericSelectCommand graphData = new GenericSelectCommand(graphDataQuery);
GenericSelectCommand backSeries = new GenericSelectCommand(backSeriesQuery);

List<Map<String, Object>> graphDataList = Collections.emptyList();
List<Map<String, Object>> backSeriesList = Collections.emptyList();
List backDataListArray = new ArrayList();

try
{

    // GET THE INITIAL LINE CHART SERIES
    Persistor.instance().executeTransact(graphData);
    graphDataList = graphData.getRows();

    // LOOK FOR ANY ADDITIONAL SERIES THAT SHOULD BE ON THE LINE CHART
    Persistor.instance().executeTransact(backSeries);
    backSeriesList = backSeries.getRows();

    // FOR EACH ADDITIONAL SERIES FOUND, RUN THE QUERY AND ADD IT TO backDataListArray
    for (int i = 0; i < backSeriesList.size(); i++)
    {
        Map<String, Object> backSeriesBean = backSeriesList.get(i);

        String backDataQuery = "exec runQuery 'getBackData', " + backSeriesBean.get("series_id");
        GenericSelectCommand backData = new GenericSelectCommand(backDataQuery);
        Persistor.instance().executeTransact(backData);
        List<Map<String, Object>> backDataList = backData.getRows();
        backDataListArray.add(backDataList);
    }
}
catch (Throwable e)
{
    System.err.println("Error: ");
    System.err.println(e.getCause());
}
finally
{
    Persistor.instance().closeSession();
}

// FOR EACH RECORD IN THE ORIGINAL QUERY, WRITE THE JSON STRING
for (int i = 0; i < graphDataList.size(); i++)
{

    StringBuilder backDataString = new StringBuilder();

    // BUILD THE BACK DATA STRING (IF THERE IS ANY)
    for (int j = 0; j < backDataListArray.size(); j++)
    {
        List<Map<String, Object>> backDataList = (List<Map<String, Object>>) backDataListArray.get(j);
        Map<String, Object> backDataBean = backDataList.get(i);
        Map<String, Object> backSeriesBean = backSeriesList.get(j);

        backDataString.append(backSeriesBean.get("the_series") + ": " + backDataBean.get("the_count") + ", ");
    }

    Map<String, Object> graphDataBean = graphDataList.get(i);

    out.println("{the_quota: " + graphDataBean.get("the_quota") + ", " + "count_pt_year: " + graphDataBean.get("count_pt_year") + ", " + backDataString + "date_string: '" + graphDataBean.get("date_string") + "'}" + (i + 1 == graphDataList.size() ? "" : "," ));
}
  • 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-27T18:49:49+00:00Added an answer on May 27, 2026 at 6:49 pm

    I would not merge the lists. I would just create an outer list for each query and then go through the outer list and return each series list. You can just create the outer list as:

    List outerList = new ArrayList();
    

    I would not worry about specifying the types for the outer list as it just makes it more complicated for little benefit.

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

Sidebar

Related Questions

I´m trying to change a spring jsp example to use freemarker. I changed all
When trying to use a custom JSP tag library, I have a variable defined
Hey all i am trying to use javascript with my jsp file as under:
I am a complete JSP beginner. I am trying to use a java.util.List in
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
I am trying to use <a4j:commandLink> in my JSP and I get the following
Trying to use Apache POI in a Eclipse JSP project. The POI jar is
I've included all jars the application requires, I'm trying to use Jetty Embedded I
I'm trying to use JQuery with JSP ang Spring MVC. In the example I'm
I am trying to use NTLM with Spring Security. When I run my index.jsp

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.