I'm using tomcat 9.0.+ and wish to use the built in connection pooling to connect to a postgres server.

I would like to understand the lookup mechanism for the next available connection. I create a context

   contextResource.setName("jdbc/sgsdb");
   contextResource.setType("javax.sql.DataSource");
   String turl =String.format("jdbc:postgresql://%s:%d/%s", host, port, dbname);
   contextResource.setProperty("url",turl);
   contextResource.setProperty("driverClassName","org.postgresql.Driver");

which names a specific database.  Then I make a user specific connection

   DataSource ds = (DataSource)env.lookup("jdbc/sgsdb");
   conn =ds.getConnection(user, pwd);

1. To access a different database do I need to make a database-specific DataSource?

2. Is the username used to locate an available connection for that user (maybe creating one if not found) or is the user overlain on an existing connection (perhaps "set role user")?



Reply via email to