## Background
Map a column data type to its corresponding Java class.
## Problem
A query returns meta information from a database:
SELECT
rb.object_schema,
rb.object_name,
rb.column_name
FROM
dictionary.resource_bundle rb
For example, this query returns (the self-referential):
dictionary, resource_bundle, column_name
Where 'dictionary' is the schema name, 'resource_bundle' is the object_name, and 'column_name' is the column_name.
It would be great to do something like:
SELECT
rb.object_schema,
rb.object_name,
rb.column_name,
rb.column_type
FROM
dictionary.resource_bundle rb
And have this query return:
dictionary, resource_bundle, column_name, varchar
Then use JDBC to discover that `varchar` is [mapped][1] to `java.lang.String`.
## Questions
1. 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?
1. In a database-neutral fashion (leveraging JDBC), how do you determine the mapping a database uses for a given data type?
[1]: http://archives.postgresql.org/pgsql-jdbc/2010-10/msg00062.php
以上就是Map database type to concrete Java class的详细内容,更多请关注web前端其它相关文章!