Postgres 的“connect"的 JDBC 对应物是什么?命令? [英] What is JDBC counterpart of Postgres' "connect" command?

查看:15
本文介绍了Postgres 的“connect"的 JDBC 对应物是什么?命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 JDBC 连接执行以下 Postgres 9.6 命令

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 ALL PRIVILEGES ON DATABASE my_db TO my_db;

connect my_db; -- THIS ONE FAILS
SET ROLE my_db;

CREATE SCHEMA my_db AUTHORIZATION my_db;

"connect" 命令因无法识别而失败.有没有办法在同一个 JDBC 连接中连接其他数据库?

"connect" command fails as not recognized. Is there way to connect other database staying within the same JDBC connection?

UPD:CONNECT TO ..."和EXEC SQL CONNECT TO ..."也失败.

UPD: "CONNECT TO ..." and "EXEC SQL CONNECT TO ..." also fail.

推荐答案

反斜杠命令不是 PostgreSQL SQL 命令,它们是 psql 命令行实用程序中的命令.在幕后,connect 只是关闭连接并打开一个新连接.

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 本身无法在连接上切换数据库.

PostgreSQL its self does not have any way to switch databases on a connection.

断开并重新连接到另一个数据库.

Disconnect and reconnect to the other DB.

这篇关于Postgres 的“connect"的 JDBC 对应物是什么?命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆