I\'m trying to execute following Postgres 9.6 commands over JDBC connection
CREATE USER my_db WITH SUPERUSER PASSWORD \'my_db\';
CREATE DATABASE my_db;
GRANT
Backslash commands are not PostgreSQL SQL commands, they're commands in the psql command-line utility. Behind the scenes, \connect just closes the connection and opens a new one.
PostgreSQL its self does not have any way to switch databases on a connection.
Disconnect and reconnect to the other DB.