pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: dmp <danap@ttc-cmc.net>
To: pgsql-jdbc@postgresql.org
To: the6campbells@gmail.com
Subject: Re: getTables not returning 10 columns etc
Date: Fri, 09 Dec 2011 10:48:26 -0700
Message-ID: <4EE249EA.40807@ttc-cmc.net> (raw)

> re documentation
> http://docs.oracle.com/javase/6/docs/api/java/sql/ResultSetMetaData.html
>
> re example
>
> Server: 9.0.4 Driver: PostgreSQL Native Driver: PostgreSQL 9.1 JDBC3
> (build 901)
>
> ResultSet rs = meta.getTables(null, null, null, null);
> ResultSetMetaData rsmd = rs.getMetaData();
> System.out.println(rsmd.getColumnCount());
>
> This will print the value of 5 not 10.
>
> Change the code to
> for (int i = 1; i <= rsmd.getColumnCount(); i++) {
>  System.out.println(rsmd.getColumnName(i));
> }
>
> http://docs.oracle.com/javase/6/docs/api/java/sql/DatabaseMetaData.html#getTables(java.lang.String,
> java.lang.String, java.lang.String, java.lang.String[])
> returns names as follows was expecting upper case names similar to
> rs.getString("TABLE_NAME")
> table_cat
> table_schem
> table_name
> table_type
> remarks

The second reference you give to the DatabaseMetaData indicates in the
javadocs information for the getTables():

"Note: Some databases may not return information for all tables."

Indeed the PostgreSQL JDBC does only return the first five as does MySQL,
but SQLite gives all ten. As far as the column names as others have said
one should not rely on any particular case defaults. I learned with the
MyJSQLView application to always stipulate names with the database identifer
to fully qualifier table and column names.

Example:

-- MyJSQLView SQL Dump
-- Version: 3.31
-- WebSite: http://myjsqlview.org
--
-- Host: 127.0.0.1
-- Generated On: 2011.12.09 AD at 09:30:36 MST
-- SQL version: PostgreSQL 9.0.1
-- Database: key_tables
--
--
-- Table structure for table "public"."keY_tAble2"
--

DROP TABLE IF EXISTS "public"."keY_tAble2";
CREATE TABLE "public"."keY_tAble2" (
     "Host" char(60) DEFAULT '' NOT NULL,
     "Db" char(64) DEFAULT '' NOT NULL,
     "Username" char(16) DEFAULT '' NOT NULL,
     "select_priv" boolean DEFAULT true NOT NULL,
     PRIMARY KEY ("Host","Db","Username")
);

--
-- Dumping data for table "public"."keY_tAble2"
--

INSERT INTO "public"."keY_tAble2" ("Host", "Db", "Username", "select_priv") 
VALUES('cindy', 'sample', 'danap', 't');

Output from getTables();

Table CAT: null
Table Schem: public
Table Name: keY_tAble2
Table Type: TABLE
Remarks: null




view thread (9+ messages)  latest in thread

Message-ID: <4EE249EA.40807@ttc-cmc.net>
Permalink:  ../4EE249EA.40807@ttc-cmc.net/
Also on:    postgresql.org/message-id/4EE249EA.40807@ttc-cmc.net

 · 

reply

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, the6campbells@gmail.com
  Subject: Re: getTables not returning 10 columns etc
  In-Reply-To: <4EE249EA.40807@ttc-cmc.net>
  References: <4EE249EA.40807@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