JDBC for SQL Server - Herong's Tutorial Examples - v3.14, by 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
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
Using Connection Pool with JDBC
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