本文介绍了与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相对应的是什么?命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 19:00