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 to java.lang.String
.
Questions
- 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?
- In a database-neutral fashion (leveraging JDBC), how do you determine the mapping a database uses for a given data type?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…