Obtain an instance of java.sql.DatabaseMetaData
from the connection object.
The names of database can be obtained via getCatalogs()
or getSchemas()
method (It depends upon the vendor of JDBC driver).
ResultSet rs=cn.getMetaData().getSchemas();
while(rs.next()) {
System.out.println(rs.getString(1));
}
Or use Connection.getCatalog()
or Connection.getSchema()
method.
In case if you are interested to get host name
or ip address
of the Oracle database server.
ResultSet rs=st.executeQuery("select UTL_INADDR.GET_HOST_NAME from dual");
while(rs.next())
System.out.println(rs.getString(1));