JDBC Tutorials - Herong's Tutorial Examples - v3.12, by Dr. Herong Yang
JDBC-ODBC - SQL Server and Driver Info
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) HerongYang.com. 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).
Table of Contents
JDBC (Java Database Connectivity) Introduction
Installing and Running Java DB - Derby
Derby (Java DB) JDBC DataSource Objects
Java DB (Derby) - DML Statements
Java DB (Derby) - ResultSet Objects of Queries
Java DB (Derby) - PreparedStatement
MySQL JDBC Driver (MySQL Connector/J)
MySQL - Reference Implementation of JdbcRowSet
MySQL - JBDC CallableStatement
MySQL CLOB (Character Large Object) - TEXT
MySQL BLOB (Binary Large Object) - BLOB
Oracle Express Edition Installation on Windows
Oracle - Reference Implementation of JdbcRowSet
Oracle - JBDC CallableStatement
Oracle CLOB (Character Large Object) - TEXT
Oracle BLOB (Binary Large Object) - BLOB
Microsoft SQL Server Express Edition
Microsoft JDBC Driver for SQL Server
Microsoft JDBC Driver - Query Statements and Result Sets
Microsoft JDBC Driver - DatabaseMetaData Object
Microsoft JDBC Driver - DDL Statements
Microsoft JDBC Driver - DML Statements
SQL Server - PreparedStatement
SQL Server CLOB (Character Large Object) - TEXT
SQL Server BLOB (Binary Large Object) - BLOB
JDBC-ODBC Bridge Driver - sun.jdbc.odbc.JdbcOdbcDriver
JDBC-ODBC Bridge Driver - Flat Text Files
JDBC-ODBC Bridge Driver - MS Access
►JDBC-ODBC Bridge Driver - MS SQL Server
JDBC-ODBC - Configuring SQL Server for TCP/IP Connection
JDBC-ODBC - Creating DSN for SQL Server 2005
JDBC-ODBC - Connecting to SQL Server 2005
►JDBC-ODBC - SQL Server and Driver Info
JDBC-ODBC - Setting Current Database
JDBC-ODBC - Looping through ResultSet
Summary of JDBC Drivers and Database Servers