Code example for ResultSet

Methods: getInt, next

0
			String sql = "select * from topology where node_id = ?";
			getRoot = conn.prepareStatement(sql);
			getRoot.setInt(1, rootID);
			rootRS = getRoot.executeQuery();
			 
			if (rootRS.next()) {
				int maxDepth = rootRS.getInt("Depth") + depth;
				 
				sql = "select * " + 
					" from node natural join topology " +  
					" where LeftNode >= ? and RightNode <= ? and Depth <= ? and tree_id = ?" +  
					" order by Depth desc "; 
				 
				getSubtree = conn.prepareStatement(sql);
				getSubtree.setInt(1, rootRS.getInt("LeftNode"));
				getSubtree.setInt(2, rootRS.getInt("RightNode"));
				getSubtree.setInt(3, maxDepth);
				getSubtree.setInt(4, rootRS.getInt("tree_id"));
				 
				subtreeRS = getSubtree.executeQuery();
				 
				subtree = buildTree(subtreeRS);
			} 
		} 
		catch(SQLException e)
		{ 
			//Auto-generated catch block 
			e.printStackTrace();
		} 
		finally 
		{ 
			ConnectionUtil.close(rootRS);
			ConnectionUtil.close(subtreeRS);
			ConnectionUtil.close(getRoot);
			ConnectionUtil.close(getSubtree);
			ConnectionUtil.close(conn);
		}