本文整理匯總了Java中com.mysql.jdbc.StringUtils類的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils類的具體用法?Java StringUtils怎麽用?Java StringUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StringUtils類屬於com.mysql.jdbc包,在下文中一共展示了StringUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testAsciiCharConversion
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
/**
* Tests character conversion bug.
*
* @throws Exception
* if there is an internal error (which is a bug).
*/
public void testAsciiCharConversion() throws Exception {
byte[] buf = new byte[10];
buf[0] = (byte) '?';
buf[1] = (byte) 'S';
buf[2] = (byte) 't';
buf[3] = (byte) 'a';
buf[4] = (byte) 't';
buf[5] = (byte) 'e';
buf[6] = (byte) '-';
buf[7] = (byte) 'b';
buf[8] = (byte) 'o';
buf[9] = (byte) 't';
String testString = "?State-bot";
String convertedString = StringUtils.toAsciiString(buf);
for (int i = 0; i < convertedString.length(); i++) {
System.out.println((byte) convertedString.charAt(i));
}
assertTrue("Converted string != test string", testString.equals(convertedString));
}
示例2: testUseOldUTF8Behavior
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
public void testUseOldUTF8Behavior() throws Exception {
Properties props = new Properties();
props.setProperty("useOldUTF8Behavior", "true");
props.setProperty("useUnicode", "true");
props.setProperty("characterEncoding", "UTF-8");
props.setProperty("logFactory", "com.mysql.jdbc.log.StandardLogger");
props.setProperty("profileSQL", "true");
StandardLogger.startLoggingToBuffer();
try {
getConnectionWithProps(props);
assertTrue(StringUtils.indexOfIgnoreCase(StandardLogger.getBuffer().toString(), "SET NAMES utf8") == -1);
} finally {
StandardLogger.dropBuffer();
}
}
示例3: 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);
}
示例4: appendXid
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
private static void appendXid(StringBuilder builder, Xid xid) {
byte[] gtrid = xid.getGlobalTransactionId();
byte[] btrid = xid.getBranchQualifier();
if (gtrid != null) {
StringUtils.appendAsHex(builder, gtrid);
}
builder.append(',');
if (btrid != null) {
StringUtils.appendAsHex(builder, btrid);
}
builder.append(',');
StringUtils.appendAsHex(builder, xid.getFormatId());
}
示例5: getInteger
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
/**
* Gets integer value from string data.
*
* @param value The value to convert.
* @return The converted string value.
*/
private static int getInteger(String value) {
if (StringUtils.isNullOrEmpty(value)) {
return 0;
}
if (value.equalsIgnoreCase("null")) {
return 0;
}
try {
return Integer.parseInt(value);
}
catch (Exception exception) {
}
return Integer.MAX_VALUE;
}
示例6: testIndexOfQuoteDoubleAware
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
/**
* Tests StringUtil.indexOfQuoteDoubleAware() method
*
* @throws Exception
*/
public void testIndexOfQuoteDoubleAware() throws Exception {
final String[] searchInDoubledQt = new String[] { "A 'strange' \"STRONG\" `SsStRiNg` to be searched in",
"A ''strange'' \"\"STRONG\"\" ``SsStRiNg`` to be searched in" };
assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(null, null, 0));
assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(null, "'", 0));
assertEquals(-1, StringUtils.indexOfQuoteDoubleAware("abc", null, 0));
assertEquals(-1, StringUtils.indexOfQuoteDoubleAware("abc", "", 0));
assertEquals(-1, StringUtils.indexOfQuoteDoubleAware("abc", "bcd", 0));
assertEquals(0, StringUtils.indexOfQuoteDoubleAware("abc", "abc", 0));
int qtPos = 0;
assertEquals(2, qtPos = StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "'", 0));
assertEquals(10, qtPos = StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "'", qtPos + 1));
assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "'", qtPos + 1));
assertEquals(12, qtPos = StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "\"", 0));
assertEquals(19, qtPos = StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "\"", qtPos + 1));
assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "\"", qtPos + 1));
assertEquals(21, qtPos = StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "`", 0));
assertEquals(30, qtPos = StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "`", qtPos + 1));
assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "`", qtPos + 1));
assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[1], "'", 0));
assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[1], "\"", 0));
assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[1], "`", 0));
}
示例7: testTableCompression
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
/**
* WL#7696 - InnoDB: Transparent page compression.
*
* Tests COMPRESSION clause in CREATE|ALTER TABLE syntax.
*
* table_option: (...) | COMPRESSION [=] {'ZLIB'|'LZ4'|'NONE'}
*/
public void testTableCompression() throws Exception {
if (!versionMeetsMinimum(5, 7, 8)) {
return;
}
// Create table with 'zlib' compression.
createTable("testTableCompression", "(c VARCHAR(15000)) COMPRESSION='ZLIB'");
this.rs = this.stmt.executeQuery("show create table testTableCompression");
assertTrue(this.rs.next());
assertTrue(StringUtils.indexOfIgnoreCase(this.rs.getString(2), "COMPRESSION='ZLIB'") >= 0);
// Alter table compression to 'lz4'.
this.stmt.execute("ALTER TABLE testTableCompression COMPRESSION='LZ4'");
this.rs = this.stmt.executeQuery("show create table testTableCompression");
assertTrue(this.rs.next());
assertTrue(StringUtils.indexOfIgnoreCase(this.rs.getString(2), "COMPRESSION='LZ4'") >= 0);
// Alter table compression to 'none'.
this.stmt.execute("ALTER TABLE testTableCompression COMPRESSION='NONE'");
this.rs = this.stmt.executeQuery("show create table testTableCompression");
assertTrue(this.rs.next());
assertTrue(StringUtils.indexOfIgnoreCase(this.rs.getString(2), "COMPRESSION='NONE'") >= 0);
}
示例8: preProcess
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
@Override
public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection conn)
throws SQLException {
if (interceptedStatement instanceof com.mysql.jdbc.PreparedStatement) {
sql = ((com.mysql.jdbc.PreparedStatement) interceptedStatement).getPreparedSql();
assertTrue("Assereet failed on: " + sql,
StringUtils.indexOfIgnoreCase(0, sql, "WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME LIKE ?") > -1);
}
return null;
}
示例9: testBug65871_testCatalogs
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
private void testBug65871_testCatalogs(Connection conn1) throws Exception {
testBug65871_testCatalog("db1`testbug65871", StringUtils.quoteIdentifier("db1`testbug65871", ((ConnectionProperties) conn1).getPedantic()), conn1);
testBug65871_testCatalog("db2`testbug65871", StringUtils.quoteIdentifier("db2`testbug65871", "\"", ((ConnectionProperties) conn1).getPedantic()),
conn1);
testBug65871_testCatalog("`db3`testbug65871`", StringUtils.quoteIdentifier("`db3`testbug65871`", "\"", ((ConnectionProperties) conn1).getPedantic()),
conn1);
}
示例10: testBug65871_testCatalog
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
private void testBug65871_testCatalog(String unquotedDbName, String quotedDbName, Connection conn1) throws Exception {
Statement st1 = null;
try {
st1 = conn1.createStatement();
// 1. catalog
st1.executeUpdate("DROP DATABASE IF EXISTS " + quotedDbName);
st1.executeUpdate("CREATE DATABASE " + quotedDbName);
this.rs = st1.executeQuery("show databases like '" + unquotedDbName + "'");
if (this.rs.next()) {
assertEquals(unquotedDbName, this.rs.getString(1));
} else {
fail("Database " + unquotedDbName + " (quoted " + quotedDbName + ") not found.");
}
testBug65871_testTable(unquotedDbName, quotedDbName, "table1`testbug65871",
StringUtils.quoteIdentifier("table1`testbug65871", ((ConnectionProperties) conn1).getPedantic()), conn1, st1);
testBug65871_testTable(unquotedDbName, quotedDbName, "table2`testbug65871",
StringUtils.quoteIdentifier("table2`testbug65871", "\"", ((ConnectionProperties) conn1).getPedantic()), conn1, st1);
testBug65871_testTable(unquotedDbName, quotedDbName, "table3\"testbug65871",
StringUtils.quoteIdentifier("table3\"testbug65871", "\"", ((ConnectionProperties) conn1).getPedantic()), conn1, st1);
testBug65871_testTable(unquotedDbName, quotedDbName, "`table4`testbug65871`",
StringUtils.quoteIdentifier("`table4`testbug65871`", "\"", ((ConnectionProperties) conn1).getPedantic()), conn1, st1);
} finally {
if (st1 != null) {
st1.executeUpdate("DROP DATABASE IF EXISTS " + quotedDbName);
st1.close();
}
}
}
示例11: isValidInetAddress
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
public static boolean isValidInetAddress(final String address) {
if (StringUtils.isEmptyOrWhitespaceOnly(address)) {
return false;
}
if (InetAddressValidator.getInstance().isValid(address)) {
return true;
}
return false;
}
示例12: testBug25047
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
/**
* Tests fix for BUG#25047 - StringUtils.indexOfIgnoreCaseRespectQuotes() isn't case-insensitive on the first character of the target.
*
* UPD: Method StringUtils.indexOfIgnoreCaseRespectQuotes() was replaced by StringUtils.indexOfIgnoreCase()
*
* @throws Exception
* if the test fails.
*/
public void testBug25047() throws Exception {
assertEquals(26, StringUtils.indexOfIgnoreCase(0, "insert into Test (TestID) values (?)", "VALUES", "`", "`", StringUtils.SEARCH_MODE__MRK_COM_WS));
assertEquals(26, StringUtils.indexOfIgnoreCase(0, "insert into Test (TestID) VALUES (?)", "values", "`", "`", StringUtils.SEARCH_MODE__MRK_COM_WS));
assertEquals(StringUtils.indexOfIgnoreCase(0, "insert into Test (TestID) values (?)", "VALUES", "`", "`", StringUtils.SEARCH_MODE__MRK_COM_WS),
StringUtils.indexOfIgnoreCase(0, "insert into Test (TestID) VALUES (?)", "VALUES", "`", "`", StringUtils.SEARCH_MODE__MRK_COM_WS));
assertEquals(StringUtils.indexOfIgnoreCase(0, "insert into Test (TestID) values (?)", "values", "`", "`", StringUtils.SEARCH_MODE__MRK_COM_WS),
StringUtils.indexOfIgnoreCase(0, "insert into Test (TestID) VALUES (?)", "values", "`", "`", StringUtils.SEARCH_MODE__MRK_COM_WS));
}
示例13: encryptPassword
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
private static byte[] encryptPassword(String password, String seed, Connection connection, String key) throws SQLException {
byte[] input = null;
try {
input = password != null ? StringUtils.getBytesNullTerminated(password, connection.getPasswordCharacterEncoding()) : new byte[] { 0 };
} catch (UnsupportedEncodingException e) {
throw SQLError.createSQLException(Messages.getString("Sha256PasswordPlugin.3", new Object[] { connection.getPasswordCharacterEncoding() }),
SQLError.SQL_STATE_GENERAL_ERROR, null);
}
byte[] mysqlScrambleBuff = new byte[input.length];
Security.xorString(input, mysqlScrambleBuff, seed.getBytes(), input.length);
return ExportControlled.encryptWithRSAPublicKey(mysqlScrambleBuff,
ExportControlled.decodeRSAPublicKey(key, ((MySQLConnection) connection).getExceptionInterceptor()),
((MySQLConnection) connection).getExceptionInterceptor());
}
示例14: ensureBaseFolderExist
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
private static String ensureBaseFolderExist(String[] args) throws Exception {
String baseFolder = "";
if (args.length > 0 ){
baseFolder = args[0];
}
if (StringUtils.isNullOrEmpty(baseFolder)) {
baseFolder = System.getProperty("user.dir");
}
return ensureFolderExist(baseFolder, "");
}
示例15: toPascalCase
import com.mysql.jdbc.StringUtils; //導入依賴的package包/類
/**
* Make get property name prettier.
*
* @param name Value to convert.
* @return Name in Pascal case
* @throws Exception
*/
public static String toPascalCase(String name) throws Exception {
if (StringUtils.isNullOrEmpty(name)) {
return name;
}
String pascalCase = "";
char newChar;
boolean toUpper = false;
char[] charArray = name.toCharArray();
for (int ctr = 0; ctr <= charArray.length - 1; ctr++)
{
if (ctr == 0)
{
newChar = Character.toUpperCase(charArray[ctr]);
pascalCase = Character.toString(newChar);
continue;
}
if (charArray[ctr] == '_')
{
toUpper = true;
continue;
}
if (toUpper)
{
newChar = Character.toUpperCase(charArray[ctr]);
pascalCase += Character.toString(newChar);
toUpper = false;
continue;
}
pascalCase += Character.toString(charArray[ctr]);
}
return pascalCase;
}