简体   繁体   中英

How to get Column names Column Data types Form Table using Eclipse Link/JPA

I am working on JPA. My requirement is get the Column Name and Data types from Table. I have Query's to do that but those are Native Query's. If I used those Native Query's, Is It will support on any Data Base like Oracle, MySql,......

Now am Using MySql with JPA working fine.

Below Query for Getting Table Column Names

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE  TABLE_SCHEMA = 'SchemaName'
AND   TABLE_NAME = 'TableName';   

I executed above Query using createNativeQuery() in JPA . Is it will support in all Data Bases. If not then how can I do this. Thank you very much.

In Oracle you can use ALL_TAB_COLUMNS table and in MS SQL server and MySQL you can use INFORMATION_SCHEMA.COLUMNS table to get information about tables and columns.

SELECT * FROM ALL_TAB_COLUMNS 
WHERE  OWNER = 'SchemaName' AND TABLE_NAME = 'TableName';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM