Created
June 2, 2017 10:26
-
-
Save qfrank/b028ce295e797a1c4a323c0cf7357d68 to your computer and use it in GitHub Desktop.
mysql table definition md5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String md5(String table) { | |
String columnDefinitionSql = "SELECT column_name,ordinal_position,column_default,is_nullable,column_type\n" + | |
"FROM information_schema.columns\n" + | |
"WHERE table_schema = '%s' AND table_name = '%s' order by column_name"; | |
MessageDigest md5 = DigestUtils.getMd5Digest(); | |
jdbcTemplate.query(String.format(columnDefinitionSql, dbSchema, table), row -> { | |
ResultSetMetaData meta = row.getMetaData(); | |
int cols = meta.getColumnCount(); | |
for (int i = 1; i <= cols; i++) { | |
md5.update(meta.getColumnName(i).getBytes()); | |
Object val = row.getObject(i); | |
if (val != null) | |
md5.update(val.toString().getBytes()); | |
} | |
}); | |
return Hex.encodeHexString(md5.digest()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment