Skip site navigation (1) Skip section navigation (2)

Re: Get a table name

From: dmp <danap(at)ttc-cmc(dot)net>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Get a table name
Date: 2009-12-28 01:42:47
Message-ID: 4B380D17.6070101@ttc-cmc.net (view raw or flat)
Thread:
Lists: pgsql-jdbc
> 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

pgsql-jdbc by date

Next:From: Viktor UsunovDate: 2009-12-28 02:52:12
Subject: Re: Bulgarian translation for the PostgreSQL JDBC driver
Previous:From: Tom LaneDate: 2009-12-28 01:38:01
Subject: Re: Get a table name

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group