databaseinfo.java

来自「一个java 代码生成器」· Java 代码 · 共 87 行

JAVA
87
字号
/**
 * Copyright (c) 2002, Siddhartha P. Chandurkar siddhartha@visioncodified.com
 * All rights reserved.
 * Licensed under the Academic Free License version 1.1
 * See the file LICENSE.TXT for details.
 * LICENSE.txt is located in the directory  <install-directory>\Jenerator
 * of your Jenertaor Installation.
 *
 **/

package com.jenerator.dbaccess;

/*<Imports>*/

import org.apache.log4j.Logger;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;

/*</Imports>*/

/**
 * Description goes here
 * It gives the Meta information for the Database.
 * It gives information regarding the Tables and columns
 * @version 0.9.0
 * @author $Author$Siddhartha P. Chandurkar
 */
public class DatabaseInfo {
    private Connection conn;
    private DatabaseMetaData DM;
    // the pattern for the tables to be queried for Meta Information
    private String pattern = "";
    private String userName = "";
    private String tableTypes[] = {
        "TABLE"
    };
    private static Logger log = Logger.getLogger(com.jenerator.dbaccess.DatabaseInfo.class.getName());

    public DatabaseInfo() throws SQLException {
        try {
            conn = new JDBCConnect().getConnection();
            DM = conn.getMetaData();
            log.info(DM.getDriverName());
            log.info(DM.getDriverVersion());
            log.info(DM.getUserName());

        } catch (SQLException e) {
            e.printStackTrace();
            log.fatal("Problem in getting connection with the Database", e);
            throw e;
        }
    }

    /**
     *  Gets a description of tables available
     *  Only table descriptions matching pattern
     */
    public ResultSet getTables() throws SQLException {
        return DM.getTables(null, DM.getUserName().toUpperCase(), pattern + "%", tableTypes);
    }

    /**
     *  This is a utility function used to display the contents of the ResultSet
     *  @param tableName 		String   	The table name for which column information
     *									has to be fetched
     */
    public ResultSet getColumns(String tableName) throws SQLException {
        return DM.getColumns(null, DM.getUserName().toUpperCase(), tableName, "%");
    }

    /**
     *  This is a utility function used to get the Primary Keys for a particular table
     * @param  tableName 		String   	The table name for which column information
     *									has to be fetched
     */
    public ResultSet getPrimaryKeys(String tableName) throws SQLException {
        return DM.getPrimaryKeys(null, null, tableName);
    }

}

// end of DatabaseInfo.java

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?