Java JDBC Database Metadata getDatabaseInfo(Connection connection_)

Here you can find the source of getDatabaseInfo(Connection connection_)

Description

get Database Info

License

Apache License

Declaration

public static Map<String, ?> getDatabaseInfo(Connection connection_)
            throws SQLException 

Method Source Code

//package com.java2s;
/**//www  .ja va  2  s.  co m
 * Copyright 2010-2011 Joseph Panico
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.sql.Connection;
import java.sql.DatabaseMetaData;

import java.sql.SQLException;

import java.util.HashMap;

import java.util.Map;

public class Main {
    public static final String DATABASE_MAJOR_VERSION_KEY = "DatabaseMajorVersion";
    public static final String DATABASE_MINOR_VERSION_KEY = "DatabaseMinorVersion";
    public static final String DATABASE_PRODUCT_NAME_KEY = "DatabaseProductName";
    public static final String DATABASE_PRODUCT_VERSION_KEY = "DatabaseProductVersion";

    public static Map<String, ?> getDatabaseInfo(Connection connection_)
            throws SQLException {
        if (connection_ == null)
            return null;
        DatabaseMetaData dbMeta = connection_.getMetaData();
        if (dbMeta == null)
            return null;
        Map<String, Object> info = new HashMap<String, Object>();
        info.put(DATABASE_MAJOR_VERSION_KEY,
                new Integer(dbMeta.getDatabaseMajorVersion()));
        info.put(DATABASE_MINOR_VERSION_KEY,
                new Integer(dbMeta.getDatabaseMinorVersion()));
        info.put(DATABASE_PRODUCT_NAME_KEY, dbMeta.getDatabaseProductName());
        info.put(DATABASE_PRODUCT_VERSION_KEY,
                dbMeta.getDatabaseProductVersion());
        return info;
    }
}

Related

  1. getColumnNames(Connection connection, String tableName)
  2. getColumnNames(String tablename, String column, Connection conn)
  3. getColumns(Connection connection, String name)
  4. getColumnSize(Connection con, String tableName, String columnName)
  5. getDatabaseId(DatabaseMetaData md)
  6. getDatabaseMetaData(Connection con)
  7. getDatabaseType(DatabaseMetaData metaData)
  8. getDBMSName(Connection conn)
  9. getDBProduct(Connection conn)