pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: davecramer (@davecramer) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
Date: Sun, 27 Mar 2016 14:20:27 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

OK, I see the challenge.

As I said the server does not provide this information unless we ask for
it. getSchemaName would have to do a query to get the name. I seem to
recall we did not want to add a performance regression.

Doesn't spring have a "Dialect" like hibernate ?

Dave Cramer

On 27 March 2016 at 10:09, Artur Geraschenko [email protected]
wrote:

> Example code:
> 
> package ru.realweb.meta;
> import org.apache.commons.dbcp2.BasicDataSource;import org.postgresql.jdbc.PgResultSetMetaData;import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;import org.springframework.jdbc.datasource.DataSourceTransactionManager;import org.springframework.jdbc.support.rowset.SqlRowSet;import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;
> import java.sql.PreparedStatement;import java.sql.ResultSetMetaData;import java.sql.SQLException;import java.util.HashMap;
> public class Test {
> 
> ```
> public static void main(String[] args) throws SQLException {
>     String driverClassName = "org.postgresql.Driver";
>     String schema = "postgresql";
>     String urlAdditional = "?encoding=UNICODE&ApplicationName=app&allowMultiQueries=true";
> 
>     BasicDataSource ds = new BasicDataSource();
>     ds.setDriverClassName(driverClassName);
>     String hostPort = "***:5432/";
>     String url = "jdbc:" + schema + "://" + hostPort + "***" + urlAdditional;
>     ds.setUrl(url);
>     ds.setUsername("***");
>     ds.setPassword("***");
>     ds.setMaxTotal(50);
>     ds.setMaxIdle(5);
> 
> 
>     String sqlQuery = "select client_id as my_client_id, price as value from client_stats limit 10";
> 
>     System.out.println("*** Pure JDBC");
>     PreparedStatement ps = ds.getConnection().prepareStatement(sqlQuery);
>     ResultSetMetaData jdbcMetaData = ps.getMetaData();
>     for (int i = 1; i <= jdbcMetaData.getColumnCount(); i++) {
>         System.out.println("\n");
>         System.out.println("jdbcMetaData.getColumnLabel() = " + jdbcMetaData.getColumnLabel(i));
> 
>         if (jdbcMetaData instanceof PgResultSetMetaData) {
>             PgResultSetMetaData pgmd = (PgResultSetMetaData) jdbcMetaData;
>             System.out.println("pgmd.getColumnName = " + pgmd.getBaseColumnName(i));
>             System.out.println("pgmd.getBaseTableName = " + pgmd.getBaseTableName(i));
>             System.out.println("pgmd.getBaseSchemaName = " + pgmd.getBaseSchemaName(i));
>         }
>     }
> 
>     System.out.println("\n\n");
>     System.out.println("*** Spring JDBC");
>     DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(ds);
>     NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(transactionManager.getDataSource());
>     SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet(sqlQuery, new HashMap<>());
>     SqlRowSetMetaData springMetaData = sqlRowSet.getMetaData();
>     for (int i = 1; i <= springMetaData.getColumnCount(); i++) {
>         System.out.println("\n");
>         System.out.println("springMetaData.getColumnLabel(i) = " + springMetaData.getColumnLabel(i));
>         System.out.println("springMetaData.getColumnName(i) = " + springMetaData.getColumnName(i));
>         System.out.println("springMetaData.getTableName(i) = " + springMetaData.getTableName(i));
>         System.out.println("springMetaData.getSchemaName(i) = " + springMetaData.getSchemaName(i));
>     }
> }
> ```
> 
> }
> 
> Will print:
> 
> **\* Pure JDBC
> 
> jdbcMetaData.getColumnLabel() = my_client_id
> pgmd.getColumnName = client_id
> pgmd.getBaseTableName = client_stats
> pgmd.getBaseSchemaName = public
> 
> jdbcMetaData.getColumnLabel() = value
> pgmd.getColumnName = price
> pgmd.getBaseTableName = client_stats
> pgmd.getBaseSchemaName = public
> 
> **\* Spring JDBC
> 
> springMetaData.getColumnLabel(i) = my_client_id
> springMetaData.getColumnName(i) = my_client_id
> springMetaData.getTableName(i) = client_stats
> springMetaData.getSchemaName(i) =
> 
> springMetaData.getColumnLabel(i) = value
> springMetaData.getColumnName(i) = value
> springMetaData.getTableName(i) = client_stats
> springMetaData.getSchemaName(i) =
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly or view it on GitHub
> https://github.com/pgjdbc/pgjdbc/issues/538#issuecomment-202069493


view thread (31+ messages)  latest in thread

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 using the --to and --cc options:
  reply via email

  To: github://pgjdbc/pgjdbc
  Cc: [email protected], [email protected]
  Subject: Re: [pgjdbc/pgjdbc] issue #538: Why getSchemaName return empty string or exists getBaseSchemaName and getColumnName return getColumnLabel?
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox