I am facing a peculiar problem while storing UUID to mysql table. I have a table with a column declaration :
expenseUUID varchar(32) primary key ,
in this column I wish to save UUID. I have generated UUID as follows:
String expenseUUID = UUID.randomUUID().toString();
expenseUUID.replaceAll("-", "");
But when I try to insert expenseUUID using JDBC , I get an error saying :
Data truncation: Data too long for column 'expenseUUID'
What should I do resolve this issue? I am stuck. I am not able to figure out what is going wrong.
You just missed to reassign your replaceAll
result to expenseUUID
var. Then your var still contains a 36 chars string.
Current :
String expenseUUID = UUID.randomUUID().toString();
expenseUUID.replaceAll("-", "");
System.out.print(expenseUUID); // 9e73f8a4-dfde-438e-9eec-ac4e94817b6b
Corrected :
String expenseUUID = UUID.randomUUID().toString();
expenseUUID = expenseUUID.replaceAll("-", "");
System.out.print(expenseUUID); // 0757c2666e934e2eb303df68bb3c9761
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.