Code example for PreparedStatement

Methods: executeQuery, setInt

0
					" 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);
		} 
		 
		return subtree;
	}