4

I want to know if there is any way to check if a column in a table is virtual in java? I was trying the ResultSetMetaData no luck there:

rsmd.isWritable(column);
rsmd.isReadOnly(column);
rsmd.isDefinitelyWritable(column);

I need to check if it is a virtual column in order to know if i should insert/modify it or not, any ideas?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • That might be DBMS dependent, so looking into the metadata information of the table should help. In case of Oracle, [ALL_TAB_COLS](http://stackoverflow.com/questions/8074963/how-to-check-column-is-virtual-in-oracle) – Maheswaran Ravisankar Oct 02 '14 at 06:56
  • Find out which actual class the metadata is - you may find it has special methods (beyond those defined for ResultSetMetaData) that can help – Bohemian Oct 02 '14 at 07:08
  • is there any java piece of code that might help? i checked every method that ResultSetMetaData has and found nothing. – Habib Gahntous Oct 02 '14 at 07:28

1 Answers1

0

Like Maheswaran Ravisankar already said, the only way to get this information is to run a query against the database. Maybe there is a Java function which does exactly this operation but I doubt that. The following query should do it for you:

select VIRTUAL_COLUMN from ALL_TAB_COLS where OWNER = :1 and TABLE_NAME = :2 and COLUMN_NAME = :3;

The result of the query will be YES or NO (YES = column is virtual).

Remember: Oracle metadata are usually stored in upper case.

o0x258
  • 336
  • 1
  • 10