From: dmp <danap@ttc-cmc.net>
To: pgsql-jdbc@postgresql.org
Subject: Re: Get a table name
Date: Sun, 27 Dec 2009 18:42:47 -0700
Message-ID: <4B380D17.6070101@ttc-cmc.net> (raw)
> Gianvito Pio wrote:
> Hi all,
> I'm trying to get the table name of a column in this way:
>
> ResultSet rs;
> try
> {
> rs = ps.executeQuery();
> ResultSetMetaData rsmd = rs.getMetaData();
> System.out.println(rsmd.getTableName(..));
>
> but the getTableName( ..) method gives me an empty string. Isn't there
> a way to know the table name of a specific field I'm obtaining? Thanks
Well that is interesting.
danap.
// Method Instances
String sqlStatementString;
Statement sqlStatement;
ResultSet rs, db_resultSet;
DatabaseMetaData dbMetaData;
ResultSetMetaData tableMetaData;
// ====================================================
// Setting Up the Column Names, Form Fields, ComboBox
// Text, Hashmaps, Special Fields, & Primary Key(s).
sqlStatementString = "SELECT * FROM " + schemaTableName + "
LIMIT 1";
System.out.println(sqlStatementString);
db_resultSet = sqlStatement.executeQuery(sqlStatementString);
// Primary Key(s)
dbMetaData = dbConnection.getMetaData();
tableMetaData = db_resultSet.getMetaData();
System.out.println("TableName:" + tableMetaData.getTableName(1));
System.out.println("CatalogName:" +
tableMetaData.getCatalogName(1));
System.out.println("SchemaName:" + tableMetaData.getSchemaName(1));
rs = dbMetaData.getPrimaryKeys(tableMetaData.getCatalogName(1),
tableMetaData.getSchemaName(1),
tableMetaData.getTableName(1));
while (rs.next())
{
if (rs.getString("COLUMN_NAME").indexOf("chunk") == -1 &&
rs.getString("TABLE_NAME").equals(tableName))
{
primaryKeys.add(rs.getString("COLUMN_NAME"));
System.out.println(rs.getString("TABLE_NAME") + " " +
rs.getString("Column_NAME"));
}
}
DBTablesPanel actionPerformed() Connection Created
SELECT * FROM "public"."keY_tAble2" LIMIT 1
TableName:
CatalogName:
SchemaName:
keY_tAble2 Host
keY_tAble2 Db
keY_tAble2 Username
DBTablesPanel actionPerformed() Connection Closed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: danap@ttc-cmc.net
Subject: Re: Get a table name
In-Reply-To: <4B380D17.6070101@ttc-cmc.net>
References: <4B380D17.6070101@ttc-cmc.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox