Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQLJ == Parent node displayed as a child if the parent node contains no children

 
sharath kv
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
PROBLEM: A parent node is displayed as a child if the parent node contains no further childern.
I need to somehow stop the 2nd sql query from being processed if it returns no results.
1st SQL Query == For the parent nodes
2nd SQL Query == For the children of the above Query(1st SQL Query).
I have the SQLJ source as follows
// This function returns a JTree type.
JTree createTree() throws SQLException
{
int id_node =0;
int clli_node=0;
#sql { select count(*) into :id_node from groups};
#sql { select count(*) into :clli_node from nes};
DefaultMutableTreeNode[] nodes = new DefaultMutableTreeNode[id_node+clli_node];
// Set the Root Node
nodes[1]=new DefaultMutableTreeNode("Root");
JTree tree = new JTree(nodes[1]);
ID_iter id_it=null;
CLLI_iter clli_it=null;
String param=null;
// Select all parents
#sql id_it={select id,fdn,level from groups connect by prior
fdn=parent_fdn start with fdn='/' };
while(id_it.next())
{
int m = id_it.level();
if(m > 1)
{
String nameg = id_it.id();
nodes[m]=new DefaultMutableTreeNode(nameg);
nodes[m-1].add(nodes[m]);
}
param =id_it.fdn();
// Select all children based on the above parent
// Query
#sql clli_it={select clli from nes where parent_fdn= aram order by clli};
while(clli_it.next())
{
int n=id_it.level();
String name=clli_it.clli();
nodes[n+1] = new DefaultMutableTreeNode(name);
nodes[n].add(nodes[n+1]);
}
}
id_it.close();
clli_it.close();
return ( jtree );
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic