本文整理汇总了Java中com.mysql.jdbc.CharsetMapping类的典型用法代码示例。如果您正苦于以下问题:Java CharsetMapping类的具体用法?Java CharsetMapping怎么用?Java CharsetMapping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CharsetMapping类属于com.mysql.jdbc包,在下文中一共展示了CharsetMapping类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testLocalInfileHooked
import com.mysql.jdbc.CharsetMapping; //导入依赖的package包/类
public void testLocalInfileHooked() throws Exception {
createTable("localInfileHooked", "(field1 int, field2 varchar(255))");
String streamData = "1\tabcd\n2\tefgh\n3\tijkl";
InputStream stream = new ByteArrayInputStream(streamData.getBytes());
try {
((com.mysql.jdbc.Statement) this.stmt).setLocalInfileInputStream(stream);
this.stmt.execute("LOAD DATA LOCAL INFILE 'bogusFileName' INTO TABLE localInfileHooked CHARACTER SET "
+ CharsetMapping.getMysqlCharsetForJavaEncoding(((MySQLConnection) this.conn).getEncoding(), (com.mysql.jdbc.Connection) this.conn));
assertEquals(-1, stream.read());
this.rs = this.stmt.executeQuery("SELECT field2 FROM localInfileHooked ORDER BY field1 ASC");
this.rs.next();
assertEquals("abcd", this.rs.getString(1));
this.rs.next();
assertEquals("efgh", this.rs.getString(1));
this.rs.next();
assertEquals("ijkl", this.rs.getString(1));
} finally {
((com.mysql.jdbc.Statement) this.stmt).setLocalInfileInputStream(null);
}
}
示例2: checkRsmdForBug13277
import com.mysql.jdbc.CharsetMapping; //导入依赖的package包/类
private void checkRsmdForBug13277(ResultSetMetaData rsmd) throws SQLException {
int i = ((com.mysql.jdbc.ConnectionImpl) this.conn)
.getMaxBytesPerChar(CharsetMapping.getJavaEncodingForMysqlCharset(((com.mysql.jdbc.Connection) this.conn).getServerCharset()));
if (i == 1) {
// This is INT field but still processed in
// ResultsetMetaData.getColumnDisplaySize
assertEquals(20, rsmd.getColumnDisplaySize(1));
}
if (versionMeetsMinimum(4, 1)) {
assertEquals(false, rsmd.isDefinitelyWritable(1));
assertEquals(true, rsmd.isReadOnly(1));
assertEquals(false, rsmd.isWritable(1));
}
}
示例3: checkRsmdForBug13277
import com.mysql.jdbc.CharsetMapping; //导入依赖的package包/类
private void checkRsmdForBug13277(ResultSetMetaData rsmd) throws SQLException {
int i = ((com.mysql.jdbc.ConnectionImpl) this.conn).getMaxBytesPerChar(CharsetMapping
.getJavaEncodingForMysqlCharset(((com.mysql.jdbc.Connection) this.conn).getServerCharset()));
if (i == 1) {
// This is INT field but still processed in
// ResultsetMetaData.getColumnDisplaySize
assertEquals(17, rsmd.getColumnDisplaySize(1));
}
if (versionMeetsMinimum(4, 1)) {
assertEquals(false, rsmd.isDefinitelyWritable(1));
assertEquals(true, rsmd.isReadOnly(1));
assertEquals(false, rsmd.isWritable(1));
}
}
示例4: testLocalInfileHooked
import com.mysql.jdbc.CharsetMapping; //导入依赖的package包/类
public void testLocalInfileHooked() throws Exception {
createTable("localInfileHooked", "(field1 int, field2 varchar(255))");
String streamData = "1\tabcd\n2\tefgh\n3\tijkl";
InputStream stream = new ByteArrayInputStream(streamData.getBytes());
try {
((com.mysql.jdbc.Statement) this.stmt).setLocalInfileInputStream(stream);
this.stmt.execute("LOAD DATA LOCAL INFILE 'bogusFileName' INTO TABLE localInfileHooked"+
" CHARACTER SET " + CharsetMapping.getMysqlEncodingForJavaEncoding(((MySQLConnection)this.conn).getEncoding(), (com.mysql.jdbc.Connection) this.conn));
assertEquals(-1, stream.read());
this.rs = this.stmt.executeQuery("SELECT field2 FROM localInfileHooked ORDER BY field1 ASC");
this.rs.next();
assertEquals("abcd", this.rs.getString(1));
this.rs.next();
assertEquals("efgh", this.rs.getString(1));
this.rs.next();
assertEquals("ijkl", this.rs.getString(1));
} finally {
((com.mysql.jdbc.Statement) this.stmt).setLocalInfileInputStream(null);
}
}
示例5: testStaticCharsetMappingConsistency
import com.mysql.jdbc.CharsetMapping; //导入依赖的package包/类
public void testStaticCharsetMappingConsistency() {
for (int i = 1; i < CharsetMapping.MAP_SIZE; i++) {
assertNotNull("Assertion failure: No mapping from charset index " + i + " to a mysql collation",
CharsetMapping.COLLATION_INDEX_TO_COLLATION_NAME[i]);
assertNotNull("Assertion failure: No mapping from charset index " + i + " to a Java character set", CharsetMapping.COLLATION_INDEX_TO_CHARSET[i]);
}
}
示例6: testBug25504578
import com.mysql.jdbc.CharsetMapping; //导入依赖的package包/类
/**
* Tests fix for Bug#25504578, CONNECT FAILS WHEN CONNECTIONCOLLATION=ISO-8859-13
*
* @throws Exception
*/
public void testBug25504578() throws Exception {
Properties p = new Properties();
String cjCharset = CharsetMapping.getJavaEncodingForMysqlCharset("latin7");
p.setProperty("characterEncoding", cjCharset);
getConnectionWithProps(p);
}
示例7: testBug11237
import com.mysql.jdbc.CharsetMapping; //导入依赖的package包/类
/**
* Tests fix for BUG#11237 useCompression=true and LOAD DATA LOCAL INFILE SQL Command
*
* @throws Exception
* if any errors occur
*/
public void testBug11237() throws Exception {
this.rs = this.stmt.executeQuery("SHOW VARIABLES LIKE 'max_allowed_packet'");
this.rs.next();
if (this.rs.getInt(2) < 4 + 1024 * 1024 * 16 - 1) {
fail("You need to increase max_allowed_packet to at least " + (4 + 1024 * 1024 * 16 - 1) + " before running this test!");
}
int requiredSize = 1024 * 1024 * 300;
int fieldLength = 1023;
int loops = requiredSize / 2 / (fieldLength + 1);
File testFile = File.createTempFile("cj-testloaddata", ".dat");
testFile.deleteOnExit();
// TODO: following cleanup doesn't work correctly during concurrent execution of testsuite
// cleanupTempFiles(testFile, "cj-testloaddata");
BufferedOutputStream bOut = new BufferedOutputStream(new FileOutputStream(testFile));
for (int i = 0; i < loops; i++) {
for (int j = 0; j < fieldLength; j++) {
bOut.write("a".getBytes()[0]);
}
bOut.write("\t".getBytes()[0]);
for (int j = 0; j < fieldLength; j++) {
bOut.write("b".getBytes()[0]);
}
bOut.write("\n".getBytes()[0]);
}
bOut.flush();
bOut.close();
createTable("testBug11237", "(field1 VARCHAR(1024), field2 VARCHAR(1024))");
StringBuilder fileNameBuf = null;
if (File.separatorChar == '\\') {
fileNameBuf = new StringBuilder();
String fileName = testFile.getAbsolutePath();
int fileNameLength = fileName.length();
for (int i = 0; i < fileNameLength; i++) {
char c = fileName.charAt(i);
if (c == '\\') {
fileNameBuf.append("/");
} else {
fileNameBuf.append(c);
}
}
} else {
fileNameBuf = new StringBuilder(testFile.getAbsolutePath());
}
Properties props = new Properties();
props.put("useCompression", "true");
Connection conn1 = getConnectionWithProps(props);
Statement stmt1 = conn1.createStatement();
int updateCount = stmt1.executeUpdate("LOAD DATA LOCAL INFILE '" + fileNameBuf.toString() + "' INTO TABLE testBug11237 CHARACTER SET "
+ CharsetMapping.getMysqlCharsetForJavaEncoding(((MySQLConnection) this.conn).getEncoding(), (com.mysql.jdbc.Connection) conn1));
assertTrue(updateCount == loops);
}
示例8: testBug23645
import com.mysql.jdbc.CharsetMapping; //导入依赖的package包/类
/**
* Tests fix for BUG#23645 - Some collations/character sets reported as
* "unknown" (specifically cias variants of existing character sets), and
* inability to override the detected server character set.
*
* @throws Exception
* if the test fails.
*/
public void testBug23645() throws Exception {
if (versionMeetsMinimum(4, 1)) {
// Part of this isn't easily testable, hence the assertion in
// CharsetMapping
// that checks for mappings existing in both directions...
// What we test here is the ability to override the character
// mapping
// when the server returns an "unknown" character encoding.
String currentlyConfiguredCharacterSet = getSingleIndexedValueWithQuery(2, "SHOW VARIABLES LIKE 'character_set_connection'").toString();
System.out.println(currentlyConfiguredCharacterSet);
String javaNameForMysqlName = CharsetMapping.getJavaEncodingForMysqlCharset(currentlyConfiguredCharacterSet);
System.out.println(javaNameForMysqlName);
for (int i = 1; i < CharsetMapping.MAP_SIZE; i++) {
String possibleCharset = CharsetMapping.getJavaEncodingForCollationIndex(i);
if (!javaNameForMysqlName.equals(possibleCharset)) {
System.out.println(possibleCharset);
Properties props = new Properties();
props.setProperty("characterEncoding", possibleCharset);
props.setProperty("com.mysql.jdbc.faultInjection.serverCharsetIndex", "65535");
Connection forcedCharConn = null;
forcedCharConn = getConnectionWithProps(props);
String forcedCharset = getSingleIndexedValueWithQuery(forcedCharConn, 2, "SHOW VARIABLES LIKE 'character_set_connection'").toString();
System.out.println(forcedCharset);
break;
}
}
}
}