很多应用程序基于java的hashcode方法,因此应用使用java的hashcode算法,但是在数据库层需要做一些与应用层次相同的hash操作,例如数据迁移操作,但是目前mysql没有提供很好的hashcode的方法,因此将java的hashcode算法整合到mysql5.1中去,作为mysql的hashcode函数使用,mysql的UDF函数代码可以从下面的URL获取源代码(在使用的过程中遇到问题,请给我留言):
http://forge.mysql.com/tools/tool.php?id=335
由于java的hashcode出来的值是一个有符号的数字,因此插入数据库的时候,需要重写下java的hashcode函数,java的源代码如下:
/**
* overload
* @param input
* @return
*/
public static long hashcode(String input) {
long MAX_VALUE = 0xffffffffL;
int …