Obtain the database vendor driver version based on semantics from the JDBC connection metadata - Java java.sql

Java examples for java.sql:Connection

Description

Obtain the database vendor driver version based on semantics from the JDBC connection metadata

Demo Code

/**/*from  ww  w  . j a v a  2  s.  co m*/
 * Database functionality abstraction utilities.
 *
 * Supported drivers:
 * - Oracle
 * - PostgreSQL
 * - MySQL (incomplete)
 * - hsql DB (incomplete)
 * - DB2 (incomplete)
 *
 * Copyright (c) 2001-2004 Marc Lavergne. All rights reserved.
 *
 * The following products are free software; Licensee can redistribute and/or 
 * modify them under the terms of   the GNU Lesser General Public License
 * (http://www.gnu.org/copyleft/lesser.html) as published by the Free Software 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-   1307  USA; 
 * either version 2.1 of the   license, or any later version:
 */
//package com.java2s;
import java.sql.*;
import java.util.logging.Logger;

public class Main {
    /**
     * Obtain the database vendor driver version based on semantics from the JDBC connection metadata
     * @param p_conn Connection object from which to extra metadata
     * @return String with the database driver version
     */
    public static String getDbDriverVer(Connection p_conn) {
        try {
            return p_conn.getMetaData().getDriverVersion();
        } catch (SQLException e_sql) {
            Logger.getAnonymousLogger().severe(e_sql.toString());
            return ""; //$NON-NLS-1$
        }
    }
}

Related Tutorials