Question

I am using com.teradata.jdbc.TeraDriver

I need to get a list of all databases to display to the user. To do that I create java.sql.Connection and call the following:

connection.getMetaData().getSchemas()

This returns the list of all teradata databases. However I would like to exclude users from this list.

To make myself more clear. If we look at teradata database in Teradata Studio Express we can see a list of all databases. In the Details for a Database there is an attribute called Database Type. The value is either "user" or "database". I would like to get via jdbc all those databases with the "database" type.

Any help will be appreciated. Thanks!

Was it helpful?

Solution

Develop your own GetSchema() method that queries the DBC.Databases view:

public static String getSchema (Connection con)
throws SQLException
{
 Statement stmt = con.createStatement () ;
 try {
  ResultSet rs = stmt.executeQuery ("SELECT DatabaseName FROM DBC.Databases WHERE DBKind = 'D'") ;
  try {
   rs.next () ;
   return rs.getString (5) ;
  } finally { rs.close () ; }
 } finally { stmt.close () ; }
}

If you want to be a little more discrete in the objects that are displayed then you can use additional logic to specify the UseXViews parameter in the connection string to return only those objects the user has been provision access to through explicit or implicit permissions.

Links point to the web sites used to provide answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top