Example usage for java.sql DatabaseMetaData getSQLKeywords

List of usage examples for java.sql DatabaseMetaData getSQLKeywords

Introduction

In this page you can find the example usage for java.sql DatabaseMetaData getSQLKeywords.

Prototype

String getSQLKeywords() throws SQLException;

Source Link

Document

Retrieves a comma-separated list of all of this database's SQL keywords that are NOT also SQL:2003 keywords.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getHSQLConnection();

    DatabaseMetaData meta = conn.getMetaData();
    String sqlKeywords = meta.getSQLKeywords();
    System.out.println("sqlKeywords:" + sqlKeywords);

    conn.close();//  ww  w.  jav  a2s.  c om
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String driverName = "com.jnetdirect.jsql.JSQLDriver";
    Class.forName(driverName);/*from w ww  . j a v a 2s.c  om*/

    String serverName = "127.0.0.1";
    String portNumber = "1433";
    String mydatabase = serverName + ":" + portNumber;
    String url = "jdbc:JSQLConnect://" + mydatabase;
    String username = "username";
    String password = "password";

    Connection connection = DriverManager.getConnection(url, username, password);
    DatabaseMetaData dbmd = connection.getMetaData();

    String[] keywords = dbmd.getSQLKeywords().split(",\\s*");
    Arrays.toString(keywords);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getMySqlConnection();
    System.out.println("Got Connection.");
    Statement st = conn.createStatement();
    st.executeUpdate("drop table survey;");
    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");

    DatabaseMetaData meta = conn.getMetaData();
    String sqlKeywords = meta.getSQLKeywords();
    System.out.println(sqlKeywords);

    st.close();//w w w  .j a  v a2 s.co  m
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();

    DatabaseMetaData mtdt = conn.getMetaData();
    System.out.println("URL in use: " + mtdt.getURL());
    System.out.println("User name: " + mtdt.getUserName());
    System.out.println("DBMS name: " + mtdt.getDatabaseProductName());
    System.out.println("DBMS version: " + mtdt.getDatabaseProductVersion());
    System.out.println("Driver name: " + mtdt.getDriverName());
    System.out.println("Driver version: " + mtdt.getDriverVersion());
    System.out.println("supp. SQL Keywords: " + mtdt.getSQLKeywords());

    conn.close();/*  w  w w  . j  ava  2s. co  m*/
}

From source file:com.hangum.tadpole.engine.manager.TadpoleSQLManager.java

/**
 * ? DB? metadata ?./*  ww  w.j a va2 s  .  com*/
 * 
 * @param searchKey
 * @param userDB
 * @param dbMetadata
 * @return
 */
public static void setMetaData(String searchKey, final UserDBDAO userDB, DatabaseMetaData dbMetaData)
        throws Exception {
    //  ??  .
    if (userDB.getDBDefine() == DBDefine.TADPOLE_SYSTEM_DEFAULT
            || userDB.getDBDefine() == DBDefine.TADPOLE_SYSTEM_MYSQL_DEFAULT)
        return;

    String strIdentifierQuoteString = "";
    try {
        strIdentifierQuoteString = dbMetaData.getIdentifierQuoteString();
    } catch (Exception e) {
        // ignore exception, not support quoteString
    }

    // https://github.com/hangum/TadpoleForDBTools/issues/412 ? ??  .
    TadpoleMetaData tadpoleMetaData = null;
    switch (userDB.getDBDefine()) {
    case ORACLE_DEFAULT:
    case TIBERO_DEFAULT:
        tadpoleMetaData = new TadpoleMetaData(strIdentifierQuoteString,
                TadpoleMetaData.STORES_FIELD_TYPE.LOWCASE_BLANK);
        break;
    case MSSQL_DEFAULT:
    case MSSQL_8_LE_DEFAULT:
    case MYSQL_DEFAULT:
    case MARIADB_DEFAULT:
    case SQLite_DEFAULT:
        tadpoleMetaData = new TadpoleMetaData(strIdentifierQuoteString,
                TadpoleMetaData.STORES_FIELD_TYPE.BLANK);
        break;
    case POSTGRE_DEFAULT:
    case TAJO_DEFAULT:
        tadpoleMetaData = new TadpoleMetaData(strIdentifierQuoteString,
                TadpoleMetaData.STORES_FIELD_TYPE.UPPERCASE_BLANK);
        break;
    default:
        tadpoleMetaData = new TadpoleMetaData(strIdentifierQuoteString, TadpoleMetaData.STORES_FIELD_TYPE.NONE);
    }

    //      SQLConstantFactory factory = new SQLConstantFactory();
    //      SQLConstants sqlConstants = factory.getDB(userDB);
    //      tmd.setKeywords(
    //            StringUtils.replace(
    //                  sqlConstants.keyword() + "|" + sqlConstants.function() + "|" + sqlConstants.constant() + "|" +sqlConstants.variable(),
    //                  "|",
    //                  ","
    //                  )
    //            );
    // set keyword
    if (userDB.getDBDefine() == DBDefine.SQLite_DEFAULT) {
        // not support keyword http://sqlite.org/lang_keywords.html
        tadpoleMetaData.setKeywords(StringUtils.join(SQLConstants.QUOTE_SQLITE_KEYWORDS, ","));
    } else if (userDB.getDBDefine() == DBDefine.MYSQL_DEFAULT | userDB.getDBDefine() == DBDefine.MYSQL_DEFAULT
            | userDB.getDBDefine() == DBDefine.ORACLE_DEFAULT
            | userDB.getDBDefine() == DBDefine.TIBERO_DEFAULT) {
        String strFullKeywords = StringUtils.join(SQLConstants.QUOTE_MYSQL_KEYWORDS, ",") + "," + dbMetadata;
        tadpoleMetaData.setKeywords(strFullKeywords);
    } else if (userDB.getDBDefine() == DBDefine.MONGODB_DEFAULT) {
        // not support this method
        tadpoleMetaData.setKeywords("");
    } else if (userDB.getDBDefine() == DBDefine.MSSQL_8_LE_DEFAULT
            || userDB.getDBDefine() == DBDefine.MSSQL_DEFAULT) {
        String strFullKeywords = StringUtils.join(SQLConstants.QUOTE_MSSQL_KEYWORDS, ",") + ","
                + dbMetaData.getSQLKeywords();
        tadpoleMetaData.setKeywords(strFullKeywords);
    } else {
        tadpoleMetaData.setKeywords(dbMetaData.getSQLKeywords());
    }

    tadpoleMetaData.setDbMajorVersion(dbMetaData.getDatabaseMajorVersion());
    tadpoleMetaData.setMinorVersion(dbMetaData.getDatabaseMinorVersion());
    dbMetadata.put(searchKey, tadpoleMetaData);
}

From source file:jef.database.DbMetaData.java

/**
 * JDBC???//from w w w  . j a  va  2 s . co  m
 * 
 * @return 
 * @throws SQLException
 */
public String[] getSQLKeywords() throws SQLException {
    Connection conn = getConnection(false);
    try {
        DatabaseMetaData databaseMetaData = conn.getMetaData();
        return org.apache.commons.lang.StringUtils.split(databaseMetaData.getSQLKeywords(), ',');
    } finally {
        releaseConnection(conn);
    }
}

From source file:org.apache.openjpa.jdbc.sql.DBDictionaryFactory.java

/**
 * Return a string containing all the property values of the given
 * database metadata./*from w ww.  j a v a  2  s  . co m*/
 */
public static String toString(DatabaseMetaData meta) throws SQLException {
    String lineSep = J2DoPrivHelper.getLineSeparator();
    StringBuilder buf = new StringBuilder(4096);
    try {
        buf.append("catalogSeparator: ").append(meta.getCatalogSeparator()).append(lineSep)
                .append("catalogTerm: ").append(meta.getCatalogTerm()).append(lineSep)
                .append("databaseProductName: ").append(meta.getDatabaseProductName()).append(lineSep)
                .append("databaseProductVersion: ").append(meta.getDatabaseProductVersion()).append(lineSep)
                .append("driverName: ").append(meta.getDriverName()).append(lineSep).append("driverVersion: ")
                .append(meta.getDriverVersion()).append(lineSep).append("extraNameCharacters: ")
                .append(meta.getExtraNameCharacters()).append(lineSep).append("identifierQuoteString: ")
                .append(meta.getIdentifierQuoteString()).append(lineSep).append("numericFunctions: ")
                .append(meta.getNumericFunctions()).append(lineSep).append("procedureTerm: ")
                .append(meta.getProcedureTerm()).append(lineSep).append("schemaTerm: ")
                .append(meta.getSchemaTerm()).append(lineSep).append("searchStringEscape: ")
                .append(meta.getSearchStringEscape()).append(lineSep).append("sqlKeywords: ")
                .append(meta.getSQLKeywords()).append(lineSep).append("stringFunctions: ")
                .append(meta.getStringFunctions()).append(lineSep).append("systemFunctions: ")
                .append(meta.getSystemFunctions()).append(lineSep).append("timeDateFunctions: ")
                .append(meta.getTimeDateFunctions()).append(lineSep).append("url: ").append(meta.getURL())
                .append(lineSep).append("userName: ").append(meta.getUserName()).append(lineSep)
                .append("defaultTransactionIsolation: ").append(meta.getDefaultTransactionIsolation())
                .append(lineSep).append("driverMajorVersion: ").append(meta.getDriverMajorVersion())
                .append(lineSep).append("driverMinorVersion: ").append(meta.getDriverMinorVersion())
                .append(lineSep).append("maxBinaryLiteralLength: ").append(meta.getMaxBinaryLiteralLength())
                .append(lineSep).append("maxCatalogNameLength: ").append(meta.getMaxCatalogNameLength())
                .append(lineSep).append("maxCharLiteralLength: ").append(meta.getMaxCharLiteralLength())
                .append(lineSep).append("maxColumnNameLength: ").append(meta.getMaxColumnNameLength())
                .append(lineSep).append("maxColumnsInGroupBy: ").append(meta.getMaxColumnsInGroupBy())
                .append(lineSep).append("maxColumnsInIndex: ").append(meta.getMaxColumnsInIndex())
                .append(lineSep).append("maxColumnsInOrderBy: ").append(meta.getMaxColumnsInOrderBy())
                .append(lineSep).append("maxColumnsInSelect: ").append(meta.getMaxColumnsInSelect())
                .append(lineSep).append("maxColumnsInTable: ").append(meta.getMaxColumnsInTable())
                .append(lineSep).append("maxConnections: ").append(meta.getMaxConnections()).append(lineSep)
                .append("maxCursorNameLength: ").append(meta.getMaxCursorNameLength()).append(lineSep)
                .append("maxIndexLength: ").append(meta.getMaxIndexLength()).append(lineSep)
                .append("maxProcedureNameLength: ").append(meta.getMaxProcedureNameLength()).append(lineSep)
                .append("maxRowSize: ").append(meta.getMaxRowSize()).append(lineSep)
                .append("maxSchemaNameLength: ").append(meta.getMaxSchemaNameLength()).append(lineSep)
                .append("maxStatementLength: ").append(meta.getMaxStatementLength()).append(lineSep)
                .append("maxStatements: ").append(meta.getMaxStatements()).append(lineSep)
                .append("maxTableNameLength: ").append(meta.getMaxTableNameLength()).append(lineSep)
                .append("maxTablesInSelect: ").append(meta.getMaxTablesInSelect()).append(lineSep)
                .append("maxUserNameLength: ").append(meta.getMaxUserNameLength()).append(lineSep)
                .append("isCatalogAtStart: ").append(meta.isCatalogAtStart()).append(lineSep)
                .append("isReadOnly: ").append(meta.isReadOnly()).append(lineSep)
                .append("nullPlusNonNullIsNull: ").append(meta.nullPlusNonNullIsNull()).append(lineSep)
                .append("nullsAreSortedAtEnd: ").append(meta.nullsAreSortedAtEnd()).append(lineSep)
                .append("nullsAreSortedAtStart: ").append(meta.nullsAreSortedAtStart()).append(lineSep)
                .append("nullsAreSortedHigh: ").append(meta.nullsAreSortedHigh()).append(lineSep)
                .append("nullsAreSortedLow: ").append(meta.nullsAreSortedLow()).append(lineSep)
                .append("storesLowerCaseIdentifiers: ").append(meta.storesLowerCaseIdentifiers())
                .append(lineSep).append("storesLowerCaseQuotedIdentifiers: ")
                .append(meta.storesLowerCaseQuotedIdentifiers()).append(lineSep)
                .append("storesMixedCaseIdentifiers: ").append(meta.storesMixedCaseIdentifiers())
                .append(lineSep).append("storesMixedCaseQuotedIdentifiers: ")
                .append(meta.storesMixedCaseQuotedIdentifiers()).append(lineSep)
                .append("storesUpperCaseIdentifiers: ").append(meta.storesUpperCaseIdentifiers())
                .append(lineSep).append("storesUpperCaseQuotedIdentifiers: ")
                .append(meta.storesUpperCaseQuotedIdentifiers()).append(lineSep)
                .append("supportsAlterTableWithAddColumn: ").append(meta.supportsAlterTableWithAddColumn())
                .append(lineSep).append("supportsAlterTableWithDropColumn: ")
                .append(meta.supportsAlterTableWithDropColumn()).append(lineSep)
                .append("supportsANSI92EntryLevelSQL: ").append(meta.supportsANSI92EntryLevelSQL())
                .append(lineSep).append("supportsANSI92FullSQL: ").append(meta.supportsANSI92FullSQL())
                .append(lineSep).append("supportsANSI92IntermediateSQL: ")
                .append(meta.supportsANSI92IntermediateSQL()).append(lineSep)
                .append("supportsCatalogsInDataManipulation: ")
                .append(meta.supportsCatalogsInDataManipulation()).append(lineSep)
                .append("supportsCatalogsInIndexDefinitions: ")
                .append(meta.supportsCatalogsInIndexDefinitions()).append(lineSep)
                .append("supportsCatalogsInPrivilegeDefinitions: ")
                .append(meta.supportsCatalogsInPrivilegeDefinitions()).append(lineSep)
                .append("supportsCatalogsInProcedureCalls: ").append(meta.supportsCatalogsInProcedureCalls())
                .append(lineSep).append("supportsCatalogsInTableDefinitions: ")
                .append(meta.supportsCatalogsInTableDefinitions()).append(lineSep)
                .append("supportsColumnAliasing: ").append(meta.supportsColumnAliasing()).append(lineSep)
                .append("supportsConvert: ").append(meta.supportsConvert()).append(lineSep)
                .append("supportsCoreSQLGrammar: ").append(meta.supportsCoreSQLGrammar()).append(lineSep)
                .append("supportsCorrelatedSubqueries: ").append(meta.supportsCorrelatedSubqueries())
                .append(lineSep).append("supportsDataDefinitionAndDataManipulationTransactions: ")
                .append(meta.supportsDataDefinitionAndDataManipulationTransactions()).append(lineSep)
                .append("supportsDataManipulationTransactionsOnly: ")
                .append(meta.supportsDataManipulationTransactionsOnly()).append(lineSep)
                .append("supportsDifferentTableCorrelationNames: ")
                .append(meta.supportsDifferentTableCorrelationNames()).append(lineSep)
                .append("supportsExpressionsInOrderBy: ").append(meta.supportsExpressionsInOrderBy())
                .append(lineSep).append("supportsExtendedSQLGrammar: ")
                .append(meta.supportsExtendedSQLGrammar()).append(lineSep).append("supportsFullOuterJoins: ")
                .append(meta.supportsFullOuterJoins()).append(lineSep).append("supportsGroupBy: ")
                .append(meta.supportsGroupBy()).append(lineSep).append("supportsGroupByBeyondSelect: ")
                .append(meta.supportsGroupByBeyondSelect()).append(lineSep).append("supportsGroupByUnrelated: ")
                .append(meta.supportsGroupByUnrelated()).append(lineSep)
                .append("supportsIntegrityEnhancementFacility: ")
                .append(meta.supportsIntegrityEnhancementFacility()).append(lineSep)
                .append("supportsLikeEscapeClause: ").append(meta.supportsLikeEscapeClause()).append(lineSep)
                .append("supportsLimitedOuterJoins: ").append(meta.supportsLimitedOuterJoins()).append(lineSep)
                .append("supportsMinimumSQLGrammar: ").append(meta.supportsMinimumSQLGrammar()).append(lineSep)
                .append("supportsMixedCaseIdentifiers: ").append(meta.supportsMixedCaseIdentifiers())
                .append(lineSep).append("supportsMixedCaseQuotedIdentifiers: ")
                .append(meta.supportsMixedCaseQuotedIdentifiers()).append(lineSep)
                .append("supportsMultipleResultSets: ").append(meta.supportsMultipleResultSets())
                .append(lineSep).append("supportsMultipleTransactions: ")
                .append(meta.supportsMultipleTransactions()).append(lineSep)
                .append("supportsNonNullableColumns: ").append(meta.supportsNonNullableColumns())
                .append(lineSep).append("supportsOpenCursorsAcrossCommit: ")
                .append(meta.supportsOpenCursorsAcrossCommit()).append(lineSep)
                .append("supportsOpenCursorsAcrossRollback: ").append(meta.supportsOpenCursorsAcrossRollback())
                .append(lineSep).append("supportsOpenStatementsAcrossCommit: ")
                .append(meta.supportsOpenStatementsAcrossCommit()).append(lineSep)
                .append("supportsOpenStatementsAcrossRollback: ")
                .append(meta.supportsOpenStatementsAcrossRollback()).append(lineSep)
                .append("supportsOrderByUnrelated: ").append(meta.supportsOrderByUnrelated()).append(lineSep)
                .append("supportsOuterJoins: ").append(meta.supportsOuterJoins()).append(lineSep)
                .append("supportsPositionedDelete: ").append(meta.supportsPositionedDelete()).append(lineSep)
                .append("supportsPositionedUpdate: ").append(meta.supportsPositionedUpdate()).append(lineSep)
                .append("supportsSchemasInDataManipulation: ").append(meta.supportsSchemasInDataManipulation())
                .append(lineSep).append("supportsSchemasInIndexDefinitions: ")
                .append(meta.supportsSchemasInIndexDefinitions()).append(lineSep)
                .append("supportsSchemasInPrivilegeDefinitions: ")
                .append(meta.supportsSchemasInPrivilegeDefinitions()).append(lineSep)
                .append("supportsSchemasInProcedureCalls: ").append(meta.supportsSchemasInProcedureCalls())
                .append(lineSep).append("supportsSchemasInTableDefinitions: ")
                .append(meta.supportsSchemasInTableDefinitions()).append(lineSep)
                .append("supportsSelectForUpdate: ").append(meta.supportsSelectForUpdate()).append(lineSep)
                .append("supportsStoredProcedures: ").append(meta.supportsStoredProcedures()).append(lineSep)
                .append("supportsSubqueriesInComparisons: ").append(meta.supportsSubqueriesInComparisons())
                .append(lineSep).append("supportsSubqueriesInExists: ")
                .append(meta.supportsSubqueriesInExists()).append(lineSep).append("supportsSubqueriesInIns: ")
                .append(meta.supportsSubqueriesInIns()).append(lineSep)
                .append("supportsSubqueriesInQuantifieds: ").append(meta.supportsSubqueriesInQuantifieds())
                .append(lineSep).append("supportsTableCorrelationNames: ")
                .append(meta.supportsTableCorrelationNames()).append(lineSep).append("supportsTransactions: ")
                .append(meta.supportsTransactions()).append(lineSep).append("supportsUnion: ")
                .append(meta.supportsUnion()).append(lineSep).append("supportsUnionAll: ")
                .append(meta.supportsUnionAll()).append(lineSep).append("usesLocalFilePerTable: ")
                .append(meta.usesLocalFilePerTable()).append(lineSep).append("usesLocalFiles: ")
                .append(meta.usesLocalFiles()).append(lineSep).append("allProceduresAreCallable: ")
                .append(meta.allProceduresAreCallable()).append(lineSep).append("allTablesAreSelectable: ")
                .append(meta.allTablesAreSelectable()).append(lineSep)
                .append("dataDefinitionCausesTransactionCommit: ")
                .append(meta.dataDefinitionCausesTransactionCommit()).append(lineSep)
                .append("dataDefinitionIgnoredInTransactions: ")
                .append(meta.dataDefinitionIgnoredInTransactions()).append(lineSep)
                .append("doesMaxRowSizeIncludeBlobs: ").append(meta.doesMaxRowSizeIncludeBlobs())
                .append(lineSep).append("supportsBatchUpdates: ").append(meta.supportsBatchUpdates());
    } catch (Throwable t) {
        // maybe abstract method error for jdbc 3 metadata method, or
        // other error
        buf.append(lineSep).append("Caught throwable: ").append(t);
    }

    return buf.toString();
}

From source file:org.apache.zeppelin.impala.SqlCompleter.java

public static Set<String> getSqlKeywordsCompletions(Connection connection) throws IOException, SQLException {

    // Add the default SQL completions
    String keywords = new BufferedReader(
            new InputStreamReader(SqlCompleter.class.getResourceAsStream("/ansi.sql.keywords"))).readLine();

    Set<String> completions = new TreeSet<>();

    if (null != connection) {
        DatabaseMetaData metaData = connection.getMetaData();

        // Add the driver specific SQL completions
        String driverSpecificKeywords = "/" + metaData.getDriverName().replace(" ", "-").toLowerCase()
                + "-sql.keywords";

        logger.info("JDBC DriverName:" + driverSpecificKeywords);

        if (SqlCompleter.class.getResource(driverSpecificKeywords) != null) {
            String driverKeywords = new BufferedReader(
                    new InputStreamReader(SqlCompleter.class.getResourceAsStream(driverSpecificKeywords)))
                            .readLine();
            keywords += "," + driverKeywords.toUpperCase();
        }/* w  w w .  j  a v a 2  s .  c om*/

        // Add the keywords from the current JDBC connection
        try {
            keywords += "," + metaData.getSQLKeywords();
        } catch (Exception e) {
            logger.debug("fail to get SQL key words from database metadata: " + e, e);
        }
        try {
            keywords += "," + metaData.getStringFunctions();
        } catch (Exception e) {
            logger.debug("fail to get string function names from database metadata: " + e, e);
        }
        try {
            keywords += "," + metaData.getNumericFunctions();
        } catch (Exception e) {
            logger.debug("fail to get numeric function names from database metadata: " + e, e);
        }
        try {
            keywords += "," + metaData.getSystemFunctions();
        } catch (Exception e) {
            logger.debug("fail to get system function names from database metadata: " + e, e);
        }
        try {
            keywords += "," + metaData.getTimeDateFunctions();
        } catch (Exception e) {
            logger.debug("fail to get time date function names from database metadata: " + e, e);
        }

        // Also allow lower-case versions of all the keywords
        keywords += "," + keywords.toLowerCase();

    }

    StringTokenizer tok = new StringTokenizer(keywords, ", ");
    while (tok.hasMoreTokens()) {
        completions.add(tok.nextToken());
    }

    return completions;
}

From source file:org.apache.zeppelin.jdbc.SqlCompleter.java

public static Set<String> getSqlKeywordsCompletions(Connection connection) throws IOException, SQLException {

    // Add the default SQL completions
    String keywords = new BufferedReader(
            new InputStreamReader(SqlCompleter.class.getResourceAsStream("/ansi.sql.keywords"))).readLine();

    Set<String> completions = new TreeSet<>();

    if (null != connection) {
        DatabaseMetaData metaData = connection.getMetaData();

        // Add the driver specific SQL completions
        String driverSpecificKeywords = "/" + metaData.getDriverName().replace(" ", "-").toLowerCase()
                + "-sql.keywords";
        logger.info("JDBC DriverName:" + driverSpecificKeywords);
        try {//from  ww  w. jav a 2 s .  c  o  m
            if (SqlCompleter.class.getResource(driverSpecificKeywords) != null) {
                String driverKeywords = new BufferedReader(
                        new InputStreamReader(SqlCompleter.class.getResourceAsStream(driverSpecificKeywords)))
                                .readLine();
                keywords += "," + driverKeywords.toUpperCase();
            }
        } catch (Exception e) {
            logger.debug(
                    "fail to get driver specific SQL completions for " + driverSpecificKeywords + " : " + e, e);
        }

        // Add the keywords from the current JDBC connection
        try {
            keywords += "," + metaData.getSQLKeywords();
        } catch (Exception e) {
            logger.debug("fail to get SQL key words from database metadata: " + e, e);
        }
        try {
            keywords += "," + metaData.getStringFunctions();
        } catch (Exception e) {
            logger.debug("fail to get string function names from database metadata: " + e, e);
        }
        try {
            keywords += "," + metaData.getNumericFunctions();
        } catch (Exception e) {
            logger.debug("fail to get numeric function names from database metadata: " + e, e);
        }
        try {
            keywords += "," + metaData.getSystemFunctions();
        } catch (Exception e) {
            logger.debug("fail to get system function names from database metadata: " + e, e);
        }
        try {
            keywords += "," + metaData.getTimeDateFunctions();
        } catch (Exception e) {
            logger.debug("fail to get time date function names from database metadata: " + e, e);
        }

        // Set all keywords to lower-case versions
        keywords = keywords.toLowerCase();

    }

    StringTokenizer tok = new StringTokenizer(keywords, ", ");
    while (tok.hasMoreTokens()) {
        completions.add(tok.nextToken());
    }

    return completions;
}

From source file:org.apache.zeppelin.mysql.SqlCompleter.java

public static Set<String> getSqlKeywordsCompletions(Connection connection) throws IOException, SQLException {

    // Add the default SQL completions
    String keywords = new BufferedReader(
            new InputStreamReader(SqlCompleter.class.getResourceAsStream("/ansi.sql.keywords"))).readLine();

    DatabaseMetaData metaData = connection.getMetaData();

    // Add the driver specific SQL completions
    String driverSpecificKeywords = "/" + metaData.getDriverName().replace(" ", "-").toLowerCase()
            + "-sql.keywords";

    logger.info("JDBC DriverName:" + driverSpecificKeywords);

    if (SqlCompleter.class.getResource(driverSpecificKeywords) != null) {
        String driverKeywords = new BufferedReader(
                new InputStreamReader(SqlCompleter.class.getResourceAsStream(driverSpecificKeywords)))
                        .readLine();/*  w ww  . j  a v  a2s. co  m*/
        keywords += "," + driverKeywords.toUpperCase();
    }

    Set<String> completions = new TreeSet<>();

    // Add the keywords from the current JDBC connection
    try {
        keywords += "," + metaData.getSQLKeywords();
    } catch (Exception e) {
        logger.debug("fail to get SQL key words from database metadata: " + e, e);
    }
    try {
        keywords += "," + metaData.getStringFunctions();
    } catch (Exception e) {
        logger.debug("fail to get string function names from database metadata: " + e, e);
    }
    try {
        keywords += "," + metaData.getNumericFunctions();
    } catch (Exception e) {
        logger.debug("fail to get numeric function names from database metadata: " + e, e);
    }
    try {
        keywords += "," + metaData.getSystemFunctions();
    } catch (Exception e) {
        logger.debug("fail to get system function names from database metadata: " + e, e);
    }
    try {
        keywords += "," + metaData.getTimeDateFunctions();
    } catch (Exception e) {
        logger.debug("fail to get time date function names from database metadata: " + e, e);
    }

    // Also allow lower-case versions of all the keywords
    keywords += "," + keywords.toLowerCase();

    StringTokenizer tok = new StringTokenizer(keywords, ", ");
    while (tok.hasMoreTokens()) {
        completions.add(tok.nextToken());
    }

    return completions;
}