Code example for PreparedStatement

Methods: executeQuery, setInt

0
		try 
		{ 
			conn = pool.getConnection();
			String sql = "select * from tree where tree_id = ?";
			statement = conn.prepareStatement(sql);
			statement.setInt(1,id);
			 
			rs = statement.executeQuery();
			if (rs.next()) {
				tree = new Tree();
				tree.setId(rs.getInt("tree_id"));
				int rootId = rs.getInt("root_id");
				RemoteNode node = getSubtree(rootId, depth);
				tree.setRootNode(node);
			} 
		} 
		catch(SQLException e)
		{ 
			//Auto-generated catch block 
			e.printStackTrace();
		} 
		finally  
		{ 
			ConnectionUtil.close(rs);
			ConnectionUtil.close(statement);
			ConnectionUtil.close(statement);
			ConnectionUtil.close(conn);
		} 
		 
		return tree;
	}