There are many scientific protocols for the tranformation of bacteria, and indeed, it forms a cornerstone of molecular biology, along with PCR, gel electrophoresis, and restriction enzymes.

But the fact that bacteria can so easily take up exogenous DNA points to the fact that they use rapid mutation as a way to cope with their environment. Not only do they swap DNA within a given species through carefully choreographed methods (conjugation via pili), but they take up totally foreign DNA to boot. They even have enzymes that facilitate integration of said DNA into their chromosomes.

This is also one reason why the rampant over-use of antibiotics is dangerous. They lead to the development of antibiotic-resistant bacteria, and once a mutation leading to drug-resistance happens, the DNA containing the gene can spread to other bacteria found within the host.

Bacteria and viruses are sneaky bastards.