Can md5 be used for encrypting data? I know that md5 shouldn't be used for password hashing because of collisions and possibility of making dictionary attacks e.g. using rainbow tables. But what about other uses? Can I use md5 for encrypting data?

Say, attacker gains access to database where sensitive data was stored using md5. He wants to know just this data that was hashed, not another data that gives this hash. Can he do it?

I know that there are better cryptographic hash functions so don't suggest to use them if md5 is enough.
If the question is "if I just had MD5 as my sole cryptographical primitive, could I use it to encrypt", well, the answer is yes, you can.  Then are a number of standard block cipher modes that don't assume invertability of the block cipher, and hence would work just find if you plopped MD5 (or rather, a keyed MD5, where you ask MD5 to hash both the input block and some keying data) right there.  Examples of such modes are CFB, OFB and Counter mode.  We don't do this in practice, both because MD5 hasn't been studied in such a mode (because the assumptions we're making on MD5 aren't the standard assumptions of hash functions, but ones concerning a large number of hashes from related images), so no one could say that it is secure), and because it would be rather slow.

On the other hand, your question would appear to be "if I have a database that includes an MD5 hash of some data, could I reconstruct what the original data was".  Well, we don't normally call that "encryption" (because there's no way to undo that operation).  And, if that is your question, the answer is no (unless you can guess what that data is, and verify it by doing an MD5 on your guess).  Even if the original data was short enough that there is unlikely to be another string that short that hashes to the same value, there is no known way (other than brute force) to find MD5 preimages, much less a specific MD5 preimage.