当前位置: 首页>>代码示例>>Java>>正文


Java MysqlConnectionPoolDataSource.setCharacterEncoding方法代码示例

本文整理汇总了Java中com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource.setCharacterEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java MysqlConnectionPoolDataSource.setCharacterEncoding方法的具体用法?Java MysqlConnectionPoolDataSource.setCharacterEncoding怎么用?Java MysqlConnectionPoolDataSource.setCharacterEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource的用法示例。


在下文中一共展示了MysqlConnectionPoolDataSource.setCharacterEncoding方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testChangeUserAndCharsets

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入方法依赖的package包/类
/**
 * Tests whether Connection.changeUser() (and thus pooled connections)
 * restore character set information correctly.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testChangeUserAndCharsets() throws Exception {
    if (versionMeetsMinimum(4, 1)) {
        MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
        ds.setURL(BaseTestCase.dbUrl);
        ds.setCharacterEncoding("utf-8");
        PooledConnection pooledConnection = ds.getPooledConnection();

        Connection connToMySQL = pooledConnection.getConnection();
        this.rs = connToMySQL.createStatement().executeQuery("SELECT @@character_set_results");
        assertTrue(this.rs.next());

        String toCheck = null;

        if (versionMeetsMinimum(4, 1, 15)) {
            if (versionMeetsMinimum(5, 0)) {
                if (versionMeetsMinimum(5, 0, 13)) {
                    toCheck = null;
                } else {
                    toCheck = "NULL";
                }
            } else {
                toCheck = null;
            }
        } else {
            toCheck = "NULL";
        }

        assertEquals(toCheck, this.rs.getString(1));

        this.rs = connToMySQL.createStatement().executeQuery("SHOW SESSION VARIABLES LIKE 'character_set_client'");
        assertTrue(this.rs.next());

        //Cause of utf8mb4
        assertEquals(0, this.rs.getString(2).indexOf("utf8"));

        connToMySQL.close();

        connToMySQL = pooledConnection.getConnection();
        this.rs = connToMySQL.createStatement().executeQuery("SELECT @@character_set_results");
        assertTrue(this.rs.next());
        assertEquals(toCheck, this.rs.getString(1));

        this.rs = connToMySQL.createStatement().executeQuery("SHOW SESSION VARIABLES LIKE 'character_set_client'");
        assertTrue(this.rs.next());

        //Cause of utf8mb4
        assertEquals(0, this.rs.getString(2).indexOf("utf8"));

        pooledConnection.getConnection().close();
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:59,代码来源:DataSourceTest.java

示例2: testChangeUserAndCharsets

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入方法依赖的package包/类
/**
 * Tests whether Connection.changeUser() (and thus pooled connections)
 * restore character set information correctly.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testChangeUserAndCharsets() throws Exception {
	if (versionMeetsMinimum(4, 1)) {
		MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
		ds.setURL(BaseTestCase.dbUrl);
		ds.setCharacterEncoding("utf-8");
		PooledConnection pooledConnection = ds.getPooledConnection();

		Connection connToMySQL = pooledConnection.getConnection();
		this.rs = connToMySQL.createStatement().executeQuery(
				"SELECT @@character_set_results");
		assertTrue(this.rs.next());
		
		String toCheck = null;
		
		if (versionMeetsMinimum(4, 1, 15)) {
			if (versionMeetsMinimum(5, 0)) {
				if (versionMeetsMinimum(5, 0, 13)) {
					toCheck = null;
				} else {
					toCheck = "NULL";
				}
			} else {
				toCheck = null;
			}
		} else {
			toCheck = "NULL";
		}
		
		assertEquals(toCheck, this.rs.getString(1));

		this.rs = connToMySQL.createStatement().executeQuery(
				"SHOW SESSION VARIABLES LIKE 'character_set_client'");
		assertTrue(this.rs.next());
		
		//Cause of utf8mb4
		assertEquals(0, this.rs.getString(2).indexOf("utf8"));

		connToMySQL.close();

		connToMySQL = pooledConnection.getConnection();
		this.rs = connToMySQL.createStatement().executeQuery(
				"SELECT @@character_set_results");
		assertTrue(this.rs.next());
		assertEquals(toCheck, this.rs.getString(1));

		this.rs = connToMySQL.createStatement().executeQuery(
				"SHOW SESSION VARIABLES LIKE 'character_set_client'");
		assertTrue(this.rs.next());

		//Cause of utf8mb4
		assertEquals(0, this.rs.getString(2).indexOf("utf8"));

		pooledConnection.getConnection().close();
	}
}
 
开发者ID:hinsenchan,项目名称:fil_project_mgmt_app_v2,代码行数:63,代码来源:DataSourceTest.java


注:本文中的com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource.setCharacterEncoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。