The method getColumns()
on the metadata is returning an empty ResultSet for Synonyms (for tables and views it\'s returning the list of columns properly).
use this way
PreparedStatement pt=coneection.preparestatement("select * from table_name");
Resultset rs=pt.executeQuery();
ResultsetMetaData rsmd=rs.getMetaData();
System.out.println(rsmd.getColumnName(coulmn_number));
System.out.println(rsmd.getColumnType(column_number));
Another way
PreparedStatement pt=coneection.preparestatement("select * from table_name");
Resultset rs=pt.executeQuery();
ResultsetMetaData rsmd=pt.getMetaData();
System.out.println(rsmd.getColumnName(coulmn_number));
System.out.println(rsmd.getColumnType(column_number));
By default the Oracle drivers does not return information on synonyms in getColumns()
. This is documented in the Oracle 11g JDBC Developer's Guide under Performance Extensions:
Considerations for getColumns
By default, the
getColumns
method does not retrieve information about the columns if a synonym is specified. To enable the retrieval of information if a synonym is specified, you must call thesetIncludeSynonyms
method on the connection as follows:( (oracle.jdbc.driver.OracleConnection)conn ).setIncludeSynonyms(true)
This will cause all subsequent
getColumns
method calls on the connection to include synonyms. This is similar tosetRemarksReporting
. Alternatively, you can set theincludeSynonyms
connection property. This is similar to theremarksReporting
connection property.However, bear in mind that if
includeSynonyms
is true, then the name of the object returned in thetable_name
column will be the synonym name, if a synonym exists. This is true even if you pass the table name togetColumns
.
Note that this last item is really important to keep in mind!