當前位置: 首頁>>代碼示例>>Java>>正文


Java StringUtils.split方法代碼示例

本文整理匯總了Java中com.mysql.jdbc.StringUtils.split方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.split方法的具體用法?Java StringUtils.split怎麽用?Java StringUtils.split使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.mysql.jdbc.StringUtils的用法示例。


在下文中一共展示了StringUtils.split方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getConnectionWithProps

import com.mysql.jdbc.StringUtils; //導入方法依賴的package包/類
protected Connection getConnectionWithProps(String url, String propsList) throws SQLException {
    Properties props = new Properties();

    if (propsList != null) {
        List<String> keyValuePairs = StringUtils.split(propsList, ",", false);

        for (String kvp : keyValuePairs) {
            List<String> splitUp = StringUtils.split(kvp, "=", false);
            StringBuilder value = new StringBuilder();

            for (int i = 1; i < splitUp.size(); i++) {
                if (i != 1) {
                    value.append("=");
                }

                value.append(splitUp.get(i));

            }

            props.setProperty(splitUp.get(0).toString().trim(), value.toString());
        }
    }

    return getConnectionWithProps(url, props);
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:26,代碼來源:BaseTestCase.java

示例2: testGetColumnPrivilegesUsingInfoSchema

import com.mysql.jdbc.StringUtils; //導入方法依賴的package包/類
/**
 * Tests the implementation of Information Schema for column privileges.
 */
public void testGetColumnPrivilegesUsingInfoSchema() throws Exception {
    String dontRunPropertyName = "com.mysql.jdbc.testsuite.cantGrant";

    if (!runTestIfSysPropDefined(dontRunPropertyName)) {
        if (versionMeetsMinimum(5, 0, 7)) {
            Properties props = new Properties();

            props.put("useInformationSchema", "true");
            Connection conn1 = null;
            Statement stmt1 = null;
            String userHostQuoted = null;

            boolean grantFailed = true;

            try {
                conn1 = getConnectionWithProps(props);
                stmt1 = conn1.createStatement();
                createTable("t1", "(c1 int)");
                this.rs = stmt1.executeQuery("SELECT USER()");
                this.rs.next();
                String user = this.rs.getString(1);
                List<String> userHost = StringUtils.split(user, "@", false);
                if (userHost.size() < 2) {
                    fail("This test requires a JDBC URL with a user, and won't work with the anonymous user. "
                            + "You can skip this test by setting the system property " + dontRunPropertyName);
                }
                userHostQuoted = "'" + userHost.get(0) + "'@'" + userHost.get(1) + "'";

                try {
                    stmt1.executeUpdate("GRANT update (c1) on t1 to " + userHostQuoted);

                    grantFailed = false;

                } catch (SQLException sqlEx) {
                    fail("This testcase needs to be run with a URL that allows the user to issue GRANTs "
                            + " in the current database. You can skip this test by setting the system property \"" + dontRunPropertyName + "\".");
                }

                if (!grantFailed) {
                    DatabaseMetaData metaData = conn1.getMetaData();
                    this.rs = metaData.getColumnPrivileges(null, null, "t1", null);
                    this.rs.next();
                    assertEquals("t1", this.rs.getString("TABLE_NAME"));
                    assertEquals("c1", this.rs.getString("COLUMN_NAME"));
                    assertEquals(userHostQuoted, this.rs.getString("GRANTEE"));
                    assertEquals("UPDATE", this.rs.getString("PRIVILEGE"));
                }
            } finally {
                if (stmt1 != null) {

                    if (!grantFailed) {
                        stmt1.executeUpdate("REVOKE UPDATE (c1) ON t1 FROM " + userHostQuoted);
                    }

                    stmt1.close();
                }

                if (conn1 != null) {
                    conn1.close();
                }
            }
        }
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:68,代碼來源:MetadataTest.java

示例3: testSplit

import com.mysql.jdbc.StringUtils; //導入方法依賴的package包/類
/**
 * Tests StringUtils.split() methods.
 */
public void testSplit() throws Exception {
    String testString = "  abstract, (contents, table of \"['figure''s'],(tables\"),  introduction  , \"methods(), ()results\", ['discussion'']', conclusion]   ";
    List<String> stringParts;

    // non existing split char, trim
    stringParts = StringUtils.split(testString, ";", true);
    assertEquals(1, stringParts.size());
    assertEquals(testString.trim(), stringParts.get(0));

    // non existing split char, don't trim
    stringParts = StringUtils.split(testString, ";", false);
    assertEquals(1, stringParts.size());
    assertEquals(testString, stringParts.get(0));

    // full split, trim
    stringParts = StringUtils.split(testString, ",", true);
    assertEquals(9, stringParts.size());
    assertEquals("abstract", stringParts.get(0));
    assertEquals("(contents", stringParts.get(1));
    assertEquals("table of \"['figure''s']", stringParts.get(2));
    assertEquals("(tables\")", stringParts.get(3));
    assertEquals("introduction", stringParts.get(4));
    assertEquals("\"methods()", stringParts.get(5));
    assertEquals("()results\"", stringParts.get(6));
    assertEquals("['discussion'']'", stringParts.get(7));
    assertEquals("conclusion]", stringParts.get(8));

    // full split, don't trim
    stringParts = StringUtils.split(testString, ",", false);
    assertEquals(9, stringParts.size());
    assertEquals("  abstract", stringParts.get(0));
    assertEquals(" (contents", stringParts.get(1));
    assertEquals(" table of \"['figure''s']", stringParts.get(2));
    assertEquals("(tables\")", stringParts.get(3));
    assertEquals("  introduction  ", stringParts.get(4));
    assertEquals(" \"methods()", stringParts.get(5));
    assertEquals(" ()results\"", stringParts.get(6));
    assertEquals(" ['discussion'']'", stringParts.get(7));
    assertEquals(" conclusion]   ", stringParts.get(8));

    // most common markers, trim
    stringParts = StringUtils.split(testString, ",", "'\"", "'\"", true);
    assertEquals(7, stringParts.size());
    assertEquals("abstract", stringParts.get(0));
    assertEquals("(contents", stringParts.get(1));
    assertEquals("table of \"['figure''s'],(tables\")", stringParts.get(2));
    assertEquals("introduction", stringParts.get(3));
    assertEquals("\"methods(), ()results\"", stringParts.get(4));
    assertEquals("['discussion'']'", stringParts.get(5));
    assertEquals("conclusion]", stringParts.get(6));

    // extended markers, trim
    stringParts = StringUtils.split(testString, ",", "'\"([{", "'\")]}", true);
    assertEquals(2, stringParts.size());
    assertEquals("abstract", stringParts.get(0));
    assertEquals("(contents, table of \"['figure''s'],(tables\"),  introduction  , \"methods(), ()results\", ['discussion'']', conclusion]",
            stringParts.get(1));

    // extended markers with overridable markers, trim
    stringParts = StringUtils.split(testString, ",", "'\"([{", "'\")]}", "'\"", true);
    assertEquals(5, stringParts.size());
    assertEquals("abstract", stringParts.get(0));
    assertEquals("(contents, table of \"['figure''s'],(tables\")", stringParts.get(1));
    assertEquals("introduction", stringParts.get(2));
    assertEquals("\"methods(), ()results\"", stringParts.get(3));
    assertEquals("['discussion'']', conclusion]", stringParts.get(4));
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:71,代碼來源:StringUtilsTest.java


注:本文中的com.mysql.jdbc.StringUtils.split方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。