开发者

Accessing hierarchical data via JDBC [closed]

开发者 https://www.devze.com 2023-03-28 02:41 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have a table Menu that has column id and parent. Can we use normal JDBC (no ORM) to load hierarchical data from the database? Can we have a generic solution f开发者_StackOverflow中文版or all databases?


First, design your database tables to store hierarchies. Secondly, use recursive CTEs (Common Table Expressions) to get the hierarchical data. Without any more information about the structure of your database tables, and the queries used, I do not think it is possible to give a more specific answer.

Note, that the queries eventually used across databases could be different (I haven't attempted verifying recursive CTE support across databases), even though recursive CTEs are a part of the SQL99 specification. So, there might be no generic SQL query, but there is certainly a generic approach that you can adopt.


If your data is in a relational database, and your schema represents it in a hierarchical way, then JDBC can extract it - assuming that you can write the appropriate queries.

I fear that there's nothing generic about. You'll have to write those queries, load the results into objects or data structures, and pass them to your UI for rendering.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号