title: Map database type to concrete Java class
body: <h2>Background</h2>
  
  <p>Map a column data type to its corresponding Java class.</p>
  
  <h2>Problem</h2>
  
  <p>A query returns meta information from a database:</p>
  
  <pre><code>SELECT
    rb.object_schema,
    rb.object_name,
    rb.column_name
  FROM
    dictionary.resource_bundle rb
  </code></pre>
  
  <p>For example, this query returns (the self-referential):</p>
  
  <pre><code>dictionary, resource_bundle, column_name
  </code></pre>
  
  <p>Where 'dictionary' is the schema name, 'resource_bundle' is the object_name, and 'column_name' is the column_name.</p>
  
  <p>It would be great to do something like:</p>
  
  <pre><code>SELECT
    rb.object_schema,
    rb.object_name,
    rb.column_name,
    rb.column_type
  FROM
    dictionary.resource_bundle rb
  </code></pre>
  
  <p>And have this query return:</p>
  
  <pre><code>dictionary, resource_bundle, column_name, varchar
  </code></pre>
  
  <p>Then use JDBC to discover that <code>varchar</code> is <a href="http://archives.postgresql.org/pgsql-jdbc/2010-10/msg00062.php" rel="nofollow noreferrer">mapped</a> to <code>java.lang.String</code>.</p>
  
  <h2>Questions</h2>
  
  <ol>
  <li>In PostgreSQL, how do you determine what type is used to store the data, given a schema name, object name (guaranteed to be table or view), and column name?</li>
  <li>In a database-neutral fashion (leveraging JDBC), how do you determine the mapping a database uses for a given data type?</li>
  </ol>