2

When using a JDBC driver for PostgreSQL in a Java program, is it correct that I can only execute SQL commands?

Can I execute psql-specific commands, such as \conninfo, \l ...?

Does JDBC directly connect to PostgreSQL server, not to any client such as psql?

Thanks.

3

1 Answer 1

4

The PostgreSQL JDBC driver does not use psql at all. It is implemented in Java and does not even use the C client shared library libpq.

There is no way to use psql commands with JDBC.

If you start psql with the -E option, you can see the SQL commands that psql sends to the server during processing its commands. That might give you a clue how you can emulate psql functionality using JDBC.

Sign up to request clarification or add additional context in comments.

3 Comments

Or better yet, use the standard JDBC API to get most of that info.
@MarkRotteveel Thanks. What methods in JDBC API to get that info?
@Tim Check the documentation of the JDBC interface java.sql.DatabaseMetaData and the PostgreSQL JDBC driver for information and look for equivalent functionality. There probably will not be a 100% equivalent for everything, but for most cases there will be something comparable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.