468,540 Members | 2,118 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,540 developers. It's quick & easy.

"\d tablename" to get column name, and column type by using JDBC

Hello,

Under mysql, we have "desc tablename" to get the detail information
about a table. My question is about to get column name, and column type
for a specific table under PostgreSQL through JDBC.

Assume we have a table named "test". Under PSQL, we can input "\d test"
to see the details about table "test" successufully. However, my main
purpose is trying to get column name, column name of a table through JDBC.

The following is the java code, by which I always get " ERROR: syntax
error at or near "\" ".

Some clues?
Emi

================================================== ==================================
Connection connection = DriverManager.getConnection(url,
"abc", "abc"); //username and pwd is "abc"
Statement stmt = connection.createStatement();
String query = "\\d test";
System.out.println("query: "+query);
ResultSet rs = stmt.executeQuery(query);

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #1
4 6196

On 02/09/2004 15:52 Ying Lu wrote:
Hello,

Under mysql, we have "desc tablename" to get the detail information
about a table. My question is about to get column name, and column type
for a specific table under PostgreSQL through JDBC.

Assume we have a table named "test". Under PSQL, we can input "\d test"
to see the details about table "test" successufully. However, my main
purpose is trying to get column name, column name of a table through
JDBC.

The following is the java code, by which I always get " ERROR: syntax
error at or near "\" ".

Some clues?


The \d command is a psql client feature. I has nothing to do with JDBC and
is not built into the server back-end (a few moments reading the source
code for psql would have shown you this). To obtain metadata through JDBC,
use the standard provided classes. If you don't know how to that then you
really need to learn JDBC. There's a good introductory tutorial on
java.sun.com

--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for
Business |
| Computer Consultants |
http://www.thomas-micro-systems-ltd.co.uk |
+------------------------------+---------------------------------------------+

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #2
have a look at java.sql.Connection.getDatabaseMetadata()
(and the object, java.sql.DatabaseMetaData it returns)

-----Messaggio originale-----
Da: pg*****************@postgresql.org
[mailto:pg*****************@postgresql.org]Per conto di Ying Lu
Inviato: giovedě 2 settembre 2004 16.53
A: pg***********@postgresql.org
Oggetto: [GENERAL] "\d tablename" to get column name, and column type by
using JDBC
Hello,

Under mysql, we have "desc tablename" to get the detail information
about a table. My question is about to get column name, and column type
for a specific table under PostgreSQL through JDBC.

Assume we have a table named "test". Under PSQL, we can input "\d test"
to see the details about table "test" successufully. However, my main
purpose is trying to get column name, column name of a table through JDBC.

The following is the java code, by which I always get " ERROR: syntax
error at or near "\" ".

Some clues?
Emi

================================================== ================
==================
Connection connection = DriverManager.getConnection(url,
"abc", "abc"); //username and pwd is "abc"
Statement stmt = connection.createStatement();
String query = "\\d test";
System.out.println("query: "+query);
ResultSet rs = stmt.executeQuery(query);

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #3
Ying Lu <yi*****@cs.concordia.ca> writes:
Hello,

Under mysql, we have "desc tablename" to get the detail information
about a table. My question is about to get column name, and column
type for a specific table under PostgreSQL through JDBC.

Assume we have a table named "test". Under PSQL, we can input "\d
test" to see the details about table "test" successufully. However,
my main purpose is trying to get column name, column name of a table
through JDBC.


The backslash commands are specific to 'psql'. From Java you'll need
to query the INFORMATION_SCHEMA or the system catalogs.

-Doug
--
Let us cross over the river, and rest under the shade of the trees.
--T. J. Jackson, 1863

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #4
Thanks a lot. Now I got it.
Doug McNaught wrote:
Ying Lu <yi*****@cs.concordia.ca> writes:
Hello,

Under mysql, we have "desc tablename" to get the detail information
about a table. My question is about to get column name, and column
type for a specific table under PostgreSQL through JDBC.

Assume we have a table named "test". Under PSQL, we can input "\d
test" to see the details about table "test" successufully. However,
my main purpose is trying to get column name, column name of a table
through JDBC.


The backslash commands are specific to 'psql'. From Java you'll need
to query the INFORMATION_SCHEMA or the system catalogs.

-Doug

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by azamka | last post: by
6 posts views Thread by Giacomo | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.