本文整理匯總了Java中com.mysql.jdbc.StringUtils.escapeQuote方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.escapeQuote方法的具體用法?Java StringUtils.escapeQuote怎麽用?Java StringUtils.escapeQuote使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mysql.jdbc.StringUtils
的用法示例。
在下文中一共展示了StringUtils.escapeQuote方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testCreateTableDataDirectory
import com.mysql.jdbc.StringUtils; //導入方法依賴的package包/類
/**
* CREATE TABLE syntax changed in 5.6GA
*
* InnoDB: Allow the location of file-per-table tablespaces to be chosen
* CREATE TABLE ... DATA DIRECTORY = 'absolute/path/to/directory/'
*
* Notes:
* - DATA DIRECTORY option can't be used with temporary tables.
* - DATA DIRECTORY and INDEX DIRECTORY can't be used together for InnoDB.
* - Using these options result in an 'option ignored' warning for servers below MySQL 5.7.7. This syntax isn't allowed for MySQL 5.7.7 and higher.
*
* @throws SQLException
*/
public void testCreateTableDataDirectory() throws SQLException {
if (versionMeetsMinimum(5, 6, 6)) {
try {
String tmpdir = null;
String separator = File.separatorChar == '\\' ? File.separator + File.separator : File.separator;
this.rs = this.stmt.executeQuery("SHOW VARIABLES WHERE Variable_name='tmpdir' or Variable_name='innodb_file_per_table'");
while (this.rs.next()) {
if ("tmpdir".equals(this.rs.getString(1))) {
tmpdir = this.rs.getString(2);
if (tmpdir.endsWith(File.separator)) {
tmpdir = tmpdir.substring(0, tmpdir.length() - 1);
}
if (File.separatorChar == '\\') {
tmpdir = StringUtils.escapeQuote(tmpdir, File.separator);
}
} else if ("innodb_file_per_table".equals(this.rs.getString(1))) {
if (!this.rs.getString(2).equals("ON")) {
fail("You need to set innodb_file_per_table to ON before running this test!");
}
}
}
dropTable("testCreateTableDataDirectorya");
dropTable("testCreateTableDataDirectoryb");
dropTable("testCreateTableDataDirectoryc");
dropTable("testCreateTableDataDirectoryd");
createTable("testCreateTableDataDirectorya", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'");
createTable("testCreateTableDataDirectoryb", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + separator + "'");
this.stmt.executeUpdate("CREATE TEMPORARY TABLE testCreateTableDataDirectoryc (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir
+ (versionMeetsMinimum(5, 7, 7) ? "' ENGINE = MyISAM" : "'"));
createTable("testCreateTableDataDirectoryd", "(x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + separator
+ "' INDEX DIRECTORY = '" + tmpdir + (versionMeetsMinimum(5, 7, 7) ? "' ENGINE = MyISAM" : "'"));
this.stmt.executeUpdate("ALTER TABLE testCreateTableDataDirectorya DISCARD TABLESPACE");
this.pstmt = this.conn
.prepareStatement("CREATE TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'");
assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);
this.pstmt = this.conn.prepareStatement(
"CREATE TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + separator + "'");
assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);
this.pstmt = this.conn.prepareStatement(
"CREATE TEMPORARY TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '" + tmpdir + "'");
assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);
this.pstmt = this.conn.prepareStatement("CREATE TABLE testCreateTableDataDirectorya (x VARCHAR(10) NOT NULL DEFAULT '') DATA DIRECTORY = '"
+ tmpdir + "' INDEX DIRECTORY = '" + tmpdir + "'");
assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);
this.pstmt = this.conn.prepareStatement("ALTER TABLE testCreateTableDataDirectorya DISCARD TABLESPACE");
assertTrue(this.pstmt instanceof com.mysql.jdbc.PreparedStatement);
} finally {
// we need to drop them even if retainArtifacts=true, otherwise temp files could be deleted by OS and DB became corrupted
dropTable("testCreateTableDataDirectorya");
dropTable("testCreateTableDataDirectoryb");
dropTable("testCreateTableDataDirectoryc");
dropTable("testCreateTableDataDirectoryd");
}
}
}