The easiest way would be to use the MySQL function to do it for you.
http://dev.mysql.com/doc/refman/4.1/en/encryption-functions.html#function_md5
If you want to do it yourself, in java, then you use the MessageDigest API. A quick google on java and MD5 will come up with plenty of examples of use.
http://java.sun.com/j2se/1.5.0/docs/api/java/security/MessageDigest.html#getInstance(java.lang.String, java.lang.String)