如何将字符串转换为GUID

问题描述 投票:0回答:1

我需要将字符串转换为GUID,在线上有很多在线教程,内容涉及将一个字符串转换为UUID而不是GUID。我正在用Java工作。

我尝试使用以下问题的帮助,但Guid似乎不是Java中的类型,GUID的构造函数没有任何参数:

How to try convert a string to a Guid

java string postgresql uuid guid
1个回答
0
投票

假设您在Postgres中将列定义为uuid,则可以使用java.util.UUID

类似:

java.util.UUID id = UUID.fromString("...."); 
PreparedStatement pstmt = connection.prepareStatement("select * from some_table where id = ?");
pstmt.setObject(1, id);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
  ... do something 
}
© www.soinside.com 2019 - 2024. All rights reserved.