It's great that you've shared the actual code you tried, but "It's not working" is a fairly useless description of the problem.
If you want help, tell people what went wrong. Did the code fail to compile? Did it compile but raise an exception when it ran? What line was the exception on? What was the exception? Did it run without any exceptions but not do what you expected? If so,
what did it do, and what did you expect?