For every http request there is tenant identifier based on which the schema is switched (datasource switching).
connection.setSchema(tenantIdentifier);
Now to secure the data access I am introducing role per schema using below code in my method getConnection ()
connection.createStatement().execute("SET ROLE " + role);
Is there any other alternative way/recommended way to set the role ?
execute("SET ROLE " + role)
? Why are you looking for an alternative?