This section describes how to get some basic information about the database server and the JDBC driver information through the DatabaseMetaData object.
If you want to know the database server name and version, or
the JDBC driver name and version, you can get them through the
DatabaseMetaData object as shown in the following sample program:
/**
* OdbcSqlServerDatabaseInfo.java
* Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
*/
import java.sql.*;
public class OdbcSqlServerDatabaseInfo {
public static void main(String [] args) {
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(
"jdbc:odbc:SQL_SERVER;user=sa;password=HerongYang");
// Database and driver info
DatabaseMetaData meta = con.getMetaData();
System.out.println("Server name: "
+ meta.getDatabaseProductName());
System.out.println("Server version: "
+ meta.getDatabaseProductVersion());
System.out.println("Driver name: "
+ meta.getDriverName());
System.out.println("Driver version: "
+ meta.getDriverVersion());
System.out.println("JDBC major version: "
+ meta.getJDBCMajorVersion());
System.out.println("JDBC minor version: "
+ meta.getJDBCMinorVersion());
con.close();
} catch (Exception e) {
System.err.println("Exception: "+e.getMessage());
}
}
}
I got the following output from this program:
Server name: Microsoft SQL Server
Server version: 09.00.1399
Driver name: JDBC-ODBC Bridge (SQLSRV32.DLL)
Driver version: 2.0001 (03.85.1117)
JDBC major version: 2
JDBC minor version: 0
The output confirms that the version the my SQL Server is 09.00.1399 (2005).