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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:46:28+00:00 2026-06-01T02:46:28+00:00

I have a result of a db query in java.sql.ResultSet that needs to be

  • 0

I have a result of a db query in java.sql.ResultSet that needs to be converted to hierarchical data structure. It looks a bit like so:

name|version|pname|code|count
n1|1.1|p1|c1|3
n1|1.1|p1|c2|2
n1|1.1|p2|c1|1
n1|1.2|p1|c1|0
n2|1.0|p1|c1|5

I need that converted into a hierarchical data structure:

N1
 + 1.1
   + p1
     + c1(3)
     + c2(2)
   + p2
     + c1(1)
 + 1.2
    + p1
      + c1(0)
N2
 + 1.0
   + p1
     + c1(5)

So my data structure can look something like this

Name {
  String name
  List<Version> versions
}

Version {
  String version
  List<PName> pnames
}

PName {
  String pName
  List<CodeCount> codeCounts
}

CodeCount {
  String code
  Integer count
}

Anyone have suggestions/code snippets on the best way to do this?

  • 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-01T02:46:30+00:00Added an answer on June 1, 2026 at 2:46 am

    There are a few ways, and how you do it depends on how robust your solution needs to be.

    One would be to just write a couple of objects that had the attributes in the database. Then you could get the result set, and iterate over it, creating a new object each time the key field (for example, “name”) changed, and adding it to a list of that object. Then you’d set the attributes appropriately. That is the “quick and dirty” solution.

    A slightly more robust way would be to use something like Hibernate to do the mapping.

    If you do decide to do that, I would also suggest redoing your tables so that they accurately reflect your object structure. It may not be needed if you just want a fast solution. But if you are seeking a robust solution for commercial or enterprise software, it’s probably a good idea.

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

Sidebar

Related Questions

I have a SQL query that is returning a table like the following: id
I have a result from a query like the below, which does not have
I would like to retrieve an ordered query result, but I need to have
I have a query that returns a result set similar to the one below:
I have a SQL query that I'm currently solving by doing two queries. I
I need to us a sql query in java that has an IN clause
I have the following bit of code that reads data from the an Oracle
If I have a sql query that uses 'distinct' (in oracle), would it be
I have a java program that runs a bunch of queries against an sql
I have this below query that I execute using java PreparedStatement: String dml=insert into

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.