日期:2014-05-17 浏览次数:20757 次
List<HashStore> hashStores = new ArrayList();
HashStore hashStore = new HashStore();
// List<String> HC = new ArrayList<String>();
// List<String> ID = new ArrayList<String>();
// public static void main(String[] args)
{
try
{ Connection conn = null;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/pic_manager?user=root&password=123&useUnicode=true&characterEncoding=gb2312";
conn= DriverManager.getConnection(url);
// System.out.println("连接一次,连接成功!");
Statement stat = (Statement) conn.createStatement();
ResultSet rs =(ResultSet) stat.executeQuery("select * from pictures ");
while (rs.next()){
String a =rs.getString(1);
String d= rs.getString(10);
hashStore.setNum(a);
System.out.println(a);
hashStore.setValue(d);
// System.out.println(d);
hashStores.add(hashStore);
}
rs.close();
stat.close();
conn.close();
conn = null;
}
conn k = new conn();
List<HashStore> hashCodes = k.aaa();
String sourceHashCode = "80f008f83b08cff0";
List<Integer> differences = new ArrayList<Integer>();
for (int i = 1; i < hashCodes.size(); i++)
{
int difference = hammingDistance(sourceHashCode, hashCodes.get(i).getValue());
differences.add(difference);
System.out.println("一共有:" +hashCodes.size());
System.out.println("这张图片ID 是:" +hashCodes.get(i).getNum());
System.out.println("这张图片ID 是:" +i);
if(difference==0 ){
System.out.println("这两张图片相同!");
}else if (difference<=5 ){
System.out.println("这两张图片相似!");
}else if (difference<=10 ){
System.out.println("这两张图片类似!");
}else {
System.out.pr