pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Philip Yarra <philip@utiba.com>
To: Oliver Jowett <oliver@opencloud.com>
Cc: Alex Stienstra <alex.stienstra@zonnet.nl>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: ResultSetMetaData.getTableName() == null
Date: Fri, 22 Sep 2006 13:50:51 +1000
Message-ID: <45135D9B.50500@utiba.com> (raw)
In-Reply-To: <451354B5.2070701@opencloud.com>
References: <20060921121816.9wvu8sr34w5c4848@webmail.versatel.nl>
	<45133DE5.4030100@utiba.com>
	<451354B5.2070701@opencloud.com>

Oliver Jowett wrote:
> Essentially I think it boiled down to "getTableName() should return the 
> table alias name", and since we don't have that available we return "". 
> There's a postgresql-specific interface to get at the underlying table 
> name (in the cases where that info is available).

Hmmm... maybe I'm missing something, but the attached test case doesn't 
use any aliases, and it returns "" (at least it does for me). Is this 
expected behaviour? If there's a postgresql-specific way to get it, 
couldn't this method implement the same way of getting it?

BTW: not a big deal for me, I can't see that I'd ever want to use that 
method. I'm just curious...

Regards, Philip.

-- 
Philip Yarra
Senior Software Engineer, Utiba Pty Ltd
philip@utiba.com

Attachments:

pg.prop (text/plain, 109B) download driver = org.postgresql.Driver url = jdbc:postgresql://your_host:5432/your_db user = you pass = your_password
rsmd.java (text/x-java, 3.1K) download import java.sql.*; import java.util.*; import java.io.*; import java.text.SimpleDateFormat; class rsmd { static Connection conn = null; static Properties prop = null; public static void main(String [] args) { try { if(args.length > 0) prop = loadProp(args[0]); else usage(); String url = prop.getProperty("url"); String user = prop.getProperty("user"); String pass = prop.getProperty("pass"); String driver = prop.getProperty("driver"); Class.forName(driver); conn = DriverManager.getConnection(url,user,pass); conn.setAutoCommit(true); createTable(); insertData(); executeSelect(); conn.commit(); dropTable(); conn.commit(); conn.close(); log("all done"); } catch(Exception ex) { log(ex); System.exit(1); } } static void executeSelect() { PreparedStatement stmt = null; try{ stmt = conn.prepareStatement("SELECT * FROM tempextest"); ResultSet rs = stmt.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); String table = rsmd.getTableName(1); if(table == null) log("null table name"); if("".equals(table)) log("empty table name"); log("table name [" + table + "]"); } catch (SQLException sqlex) { log(sqlex); closeStatement(stmt); } } static void createTable() { log("Creating table tempextest"); PreparedStatement stmt = null; try { stmt = conn.prepareStatement("CREATE TABLE tempextest(id INT PRIMARY KEY)"); stmt.executeUpdate(); } catch (SQLException sqlex) { log(sqlex); log("error creating table tempextest, can't proceed"); closeStatement(stmt); System.exit(1); } log("Table tempextest created"); } static void insertData() { log("Inserting data into table tempextest"); PreparedStatement stmt = null; try { stmt = conn.prepareStatement("INSERT INTO tempextest(id) VALUES (42)"); stmt.executeUpdate(); } catch (SQLException sqlex) { log(sqlex); log("error inserting data into table tempextest, can't proceed"); closeStatement(stmt); System.exit(1); } log("Table tempextest created"); } static void dropTable() { log("Dropping table tempextest"); PreparedStatement stmt = null; try { stmt = conn.prepareStatement("DROP TABLE tempextest"); stmt.executeUpdate(); } catch (SQLException sqlex) { log(sqlex); closeStatement(stmt); } log("Table tempextest dropped"); } static Properties loadProp(String fileName) { try{ Properties prop = new Properties(); FileInputStream fis = new FileInputStream(fileName); prop.load(fis); return prop; } catch (Exception ex) { log("exception loading properties: " + ex); usage(); } return null; } static void usage() { System.err.println("Usage: java rsmd propfile"); System.exit(1); } static void log(String msg) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S"); System.out.println(sdf.format(new java.util.Date()) + ":" + msg); } static void log(Exception ex) { log(ex.toString()); ex.printStackTrace(); } static void log(Object o) { log(o.toString()); } static void closeStatement(Statement st) { try{ st.close(); }catch(SQLException sqlex) { log(sqlex); } } }

view thread (13+ messages)  latest in thread

Message-ID: <45135D9B.50500@utiba.com>
Permalink:  ../45135D9B.50500@utiba.com/
Also on:    postgresql.org/message-id/45135D9B.50500@utiba.com

 · 

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: philip@utiba.com, oliver@opencloud.com, alex.stienstra@zonnet.nl
  Subject: Re: ResultSetMetaData.getTableName() == null
  In-Reply-To: <45135D9B.50500@utiba.com>
  References: <20060921121816.9wvu8sr34w5c4848@webmail.versatel.nl> <45133DE5.4030100@utiba.com> <451354B5.2070701@opencloud.com> <45135D9B.50500@utiba.com>

* 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