Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

Using Database Metadata

To query a database for information about what it supports, the Microsoft SQL Server 2005 JDBC Driver implements the SQLServerDatabaseMetaData class. This class contains numerous methods that return information in the form of a single value, or as a result set.

To create a SQLServerDatabaseMetaData object, you can use the getMetaData method of the SQLServerConnection class to get information about the database that it is connected to.

In the following example, an open connection to the SQL Server 2005 AdventureWorks sample database is passed in to the function, the getMetaData method of the SQLServerConnection class is used to return a SQLServerDatabaseMetadata object, and then various methods of the SQLServerDatabaseMetaData object are used to display information about the driver, driver version, database name, and database version.

public static void getDatabaseMetaData(Connection con) {
   try {
      DatabaseMetaData dbmd = con.getMetaData();
      System.out.println("dbmd:driver version = " + dbmd.getDriverVersion());
      System.out.println("dbmd:driver name = " + dbmd.getDriverName());
      System.out.println("db name = " + dbmd.getDatabaseProductName());
      System.out.println("db ver = " + dbmd.getDatabaseProductVersion());
   }
   catch (Exception e) {
      e.printStackTrace();
   }
}

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.