What kind of X-ray diffraction are you taking about? It sounds like you are refering to powder X-ray diffraction. Comparing you diffraction pattern to a database file gives you a good idea about the sample. If it is exactly the compound from the literature all peaks have to be present and in principle also the intensities have to be accordingly as well.
You can also do Rietveld refinement of you PXRD data, this have confirm the structure as well but it needs more work then just comparing 2 files.
A better way would be to do single crystal diffraction, this gives you the best confirmation if you are looking at the same crystal structure.
Since you haven't told the compounds you are looking at it is hard to give any further answers from my point of view.
Its not only matching the 2 theta of obtained graph with 2 theta of available JCPDS file, simultaneously you have to match the intensity of peaks corresponding to 2 theta values.If JCPDS file of your compound is available then match the peak position and intensity and if not available then first match your compound with the JCPDS of reactant species, whether the compound you wants to prepare, is prepared or not.
If the compound you prepared is different, that means something was prepared, then collect JCPDS of all probable compositions containing same elements your compound had and match them all with your compound, basically try to match high intensity peak of yours with the JCPDS, if that matches then check all other peaks.
In addition to Dr. Janka and Tomar, FullProf is the best way to do it.
Actually JCPDS cards provide the known phases that identified up to now. There is always possibility that you have extra phases in your sample. These extra phases should be found by trying. And as Ms. Tomar said, not only the peaks but their intensities are also essential for fitting. And this can be possible with FullProf. There are several programs , I heard "Maud".