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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With