Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading UUID from result set in Postgres JDBC

I'm using UUID for my id column, I'm looking for a way to retrieve the data inside my Java application. I can't find a method in ResultSet for getting a UUID. How would I go about getting the UUID?

like image 593
Arya Avatar asked May 22 '19 22:05

Arya


People also ask

How is UUID stored in Postgres?

PostgreSQL allows you store and compare UUID values but it does not include functions for generating the UUID values in its core. Instead, it relies on the third-party modules that provide specific algorithms to generate UUIDs.

Does Postgres support UUID?

Postgres natively supports UUID as a data type, even capable of being indexed and used as primary key. But to generate a UUID value, such as to establish a default value for a column, you need a Postgres extension (a plugin).

What is the data type for UUID in PostgreSQL?

What is the Postgres UUID Type? The Postgres UUID data type stores UUIDs as defined by RFC 4122, which are 128-bit quantities generated by algorithms that minimize the probability of having duplicate identifiers. A UUID comprises of 32 hexadecimal digits, represented in groups of 8,4,4,4 and 12.

Is Postgres unique UUID?

The data type uuid stores Universally Unique Identifiers (UUID) as defined by RFC 4122, ISO/IEC 9834-8:2005, and related standards. (Some systems refer to this data type as a globally unique identifier, or GUID, instead.)


1 Answers

Here is how it's done for anyone who searches

(java.util.UUID) result.getObject("id")

or

result.getObject("id", java.util.UUID.class)
like image 75
Arya Avatar answered Sep 26 '22 12:09

Arya