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


Java MysqlConnectionPoolDataSource类代码示例

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


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

示例1: getDataSource

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入依赖的package包/类
@Override
public DataSource getDataSource() {

    MysqlConnectionPoolDataSource dataSource = new MysqlConnectionPoolDataSource();// do not use connection pool
    dataSource.setServerName(this.host);
    dataSource.setPort(this.port);
    dataSource.setDatabaseName(this.db);
    dataSource.setUser(this.user);
    dataSource.setPassword(this.password);
    dataSource.setAllowMultiQueries(true);

    return dataSource;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:14,代码来源:DbConnMySQL.java

示例2: testBug62452

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入依赖的package包/类
/**
 * Tests fix for BUG#62452 - NPE thrown in JDBC4MySQLPooledException when statement is closed.
 * 
 * @throws Exception
 */
public void testBug62452() throws Exception {
    PooledConnection con = null;

    MysqlConnectionPoolDataSource pds = new MysqlConnectionPoolDataSource();
    pds.setUrl(dbUrl);
    con = pds.getPooledConnection();
    assertTrue(con instanceof JDBC4MysqlPooledConnection);
    testBug62452WithConnection(con);

    MysqlXADataSource xads = new MysqlXADataSource();
    xads.setUrl(dbUrl);

    xads.setPinGlobalTxToPhysicalConnection(false);
    con = xads.getXAConnection();
    assertTrue(con instanceof JDBC4MysqlXAConnection);
    testBug62452WithConnection(con);

    xads.setPinGlobalTxToPhysicalConnection(true);
    con = xads.getXAConnection();
    assertTrue(con instanceof JDBC4SuspendableXAConnection);
    testBug62452WithConnection(con);

}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:29,代码来源:ConnectionRegressionTest.java

示例3: testBug35810

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入依赖的package包/类
public void testBug35810() throws Exception {
    int defaultConnectTimeout = ((ConnectionProperties) this.conn).getConnectTimeout();
    int nonDefaultConnectTimeout = defaultConnectTimeout + 1000 * 2;
    MysqlConnectionPoolDataSource cpds = new MysqlConnectionPoolDataSource();
    String dsUrl = BaseTestCase.dbUrl;
    if (dsUrl.indexOf("?") == -1) {
        dsUrl += "?";
    } else {
        dsUrl += "&";
    }

    dsUrl += "connectTimeout=" + nonDefaultConnectTimeout;
    cpds.setUrl(dsUrl);

    Connection dsConn = cpds.getPooledConnection().getConnection();
    int configuredConnectTimeout = ((ConnectionProperties) dsConn).getConnectTimeout();

    assertEquals("Connect timeout spec'd by URL didn't take", nonDefaultConnectTimeout, configuredConnectTimeout);
    assertFalse("Connect timeout spec'd by URL didn't take", defaultConnectTimeout == configuredConnectTimeout);
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:21,代码来源:DataSourceRegressionTest.java

示例4: setUpMySqlResource

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入依赖的package包/类
/**
     * example code to setup Mysql resource for JNDI lookup by JPA
     * implementation (EclipseLink here) You may follow this model for
     * registering Database resources, you also have to expose your resource's
     * related jars to the server classpath in the maven pom file (checkout the
     * execution with id 'jetty-classpath' in this project's pom.xml file).
     */
    private static void setUpMySqlResource() {
        try {
            MysqlConnectionPoolDataSource dataPool = new MysqlConnectionPoolDataSource();
            dataPool.setURL(conf.getProperty("url"));
            dataPool.setUser(conf.getProperty("user"));
            dataPool.setPassword(conf.getProperty("password"));
            if (conf.getProperty("DB_useSSL").equalsIgnoreCase("true")) {
                dataPool.setUseSSL(true);
                dataPool.setRequireSSL(true);
                System.setProperty("javax.net.ssl.trustStore", conf.getProperty("keystorePath"));
                System.setProperty("javax.net.ssl.trustStorePassword", conf.getProperty("keystorePass"));
                // debugging ssl connection ...
//                System.setProperty("javax.net.debug", "all");
            }
            new Resource(null, "jdbc/conName", dataPool);
        } catch (NamingException ex) {
            // unlikely
            logger.info("Error setting up Mysql resource \n" + ex);
        }
    }
 
开发者ID:korena,项目名称:service-base,代码行数:28,代码来源:JServer.java

示例5: testBug62452

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入依赖的package包/类
/**
 * Tests fix for BUG#62452 - NPE thrown in JDBC4MySQLPooledException when statement is closed.
 * 
 * @throws Exception
 */
public void testBug62452() throws Exception {
    PooledConnection con = null;

    MysqlConnectionPoolDataSource pds = new MysqlConnectionPoolDataSource();
    pds.setUrl(dbUrl);
    con = pds.getPooledConnection();
    assertTrue(con instanceof JDBC4MysqlPooledConnection);
    testBug62452WithConnection(con);
    
    MysqlXADataSource xads = new MysqlXADataSource();
    xads.setUrl(dbUrl);

    xads.setPinGlobalTxToPhysicalConnection(false);
    con = xads.getXAConnection();
    assertTrue(con instanceof JDBC4MysqlXAConnection);
    testBug62452WithConnection(con);

    xads.setPinGlobalTxToPhysicalConnection(true);
    con = xads.getXAConnection();
    assertTrue(con instanceof JDBC4SuspendableXAConnection);
    testBug62452WithConnection(con);

}
 
开发者ID:zerobane,项目名称:cloudera-cli-scripts,代码行数:29,代码来源:ConnectionRegressionTest.java

示例6: testBug35810

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入依赖的package包/类
public void testBug35810() throws Exception {
	int defaultConnectTimeout = ((ConnectionProperties) this.conn).getConnectTimeout();
	int nonDefaultConnectTimeout = defaultConnectTimeout + 1000 * 2;
	MysqlConnectionPoolDataSource cpds = new MysqlConnectionPoolDataSource();
	String dsUrl = BaseTestCase.dbUrl;
	if (dsUrl.indexOf("?") == -1) {
		dsUrl += "?";
	} else {
		dsUrl += "&";
	}
	
	dsUrl += "connectTimeout=" + nonDefaultConnectTimeout;
	cpds.setUrl(dsUrl);
	
	Connection dsConn = cpds.getPooledConnection().getConnection();
	int configuredConnectTimeout = ((ConnectionProperties) dsConn).getConnectTimeout();
	
	assertEquals("Connect timeout spec'd by URL didn't take", nonDefaultConnectTimeout, configuredConnectTimeout);
	assertFalse("Connect timeout spec'd by URL didn't take", defaultConnectTimeout == configuredConnectTimeout);
}
 
开发者ID:hinsenchan,项目名称:fil_project_mgmt_app_v2,代码行数:21,代码来源:DataSourceRegressionTest.java

示例7: testBug34937

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入依赖的package包/类
public void testBug34937() throws Exception {
    com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource ds = new com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource();
    StringBuilder urlBuf = new StringBuilder();
    urlBuf.append(getMasterSlaveUrl());
    urlBuf.append("?");
    Properties props = getHostFreePropertiesFromTestsuiteUrl();
    String key = null;

    Enumeration<Object> keyEnum = props.keys();

    while (keyEnum.hasMoreElements()) {
        key = (String) keyEnum.nextElement();
        urlBuf.append(key);
        urlBuf.append("=");
        urlBuf.append(props.get(key));
        urlBuf.append("&");
    }

    String url = urlBuf.toString();
    url = "jdbc:mysql:replication:" + url.substring(url.indexOf("jdbc:mysql:") + "jdbc:mysql:".length());
    ds.setURL(url);
    Connection replConn = ds.getPooledConnection().getConnection();

    boolean readOnly = false;

    for (int i = 0; i < 10; i++) {
        this.rs = replConn.createStatement().executeQuery("SELECT 1");
        assertTrue(this.rs.next());
        this.rs = replConn.prepareStatement("SELECT 1").executeQuery();
        assertTrue(this.rs.next());
        readOnly = !readOnly;
        replConn.setReadOnly(readOnly);
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:35,代码来源:ConnectionRegressionTest.java

示例8: testBug48486

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入依赖的package包/类
public void testBug48486() throws Exception {

        Properties props = new NonRegisteringDriver().parseURL(dbUrl, null);
        String host = props.getProperty(NonRegisteringDriver.HOST_PROPERTY_KEY, "localhost");
        String port = props.getProperty(NonRegisteringDriver.PORT_PROPERTY_KEY, "3306");

        String hostSpec = host;

        if (!NonRegisteringDriver.isHostPropertiesList(host)) {
            hostSpec = host + ":" + port;
        }

        String database = props.getProperty(NonRegisteringDriver.DBNAME_PROPERTY_KEY);
        removeHostRelatedProps(props);
        props.remove(NonRegisteringDriver.DBNAME_PROPERTY_KEY);

        StringBuilder configs = new StringBuilder();
        for (@SuppressWarnings("rawtypes")
        Map.Entry entry : props.entrySet()) {
            configs.append(entry.getKey());
            configs.append("=");
            configs.append(entry.getValue());
            configs.append("&");
        }

        String newUrl = String.format("jdbc:mysql:loadbalance://%s,%s/%s?%s", hostSpec, hostSpec, database, configs.toString());

        MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
        ds.setUrl(newUrl);

        Connection c = ds.getPooledConnection().getConnection();
        this.rs = c.createStatement().executeQuery("SELECT 1");
        this.rs = c.prepareStatement("SELECT 1").executeQuery();
    }
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:35,代码来源:ConnectionRegressionTest.java

示例9: testBug58728

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入依赖的package包/类
/**
 * Tests fix for Bug#58728, NPE in com.mysql.jdbc.jdbc2.optional.StatementWrappe.getResultSet()
 * ((com.mysql.jdbc.ResultSetInternalMethods) rs).setWrapperStatement(this);
 * when rs is null
 */
public void testBug58728() throws Exception {
    createTable("testbug58728", "(Id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, txt VARCHAR(50))", "InnoDB");
    this.stmt.executeUpdate("INSERT INTO testbug58728 VALUES (NULL, 'Text 1'), (NULL, 'Text 2')");

    MysqlConnectionPoolDataSource pds = new MysqlConnectionPoolDataSource();
    pds.setUrl(dbUrl);
    Statement stmt1 = pds.getPooledConnection().getConnection().createStatement();
    stmt1.executeUpdate("UPDATE testbug58728 SET txt = 'New text' WHERE Id > 0");
    ResultSet rs1 = stmt1.getResultSet();
    stmt1.close();
    if (rs1 != null) {
        rs1.close();
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:20,代码来源:StatementRegressionTest.java

示例10: setUp

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入依赖的package包/类
/**
 * Set up test case before a test is run.
 * 
 * @throws Exception
 */
@Override
public void setUp() throws Exception {
    super.setUp();

    // Reset event count.
    this.closeEventCount = 0;
    this.connectionErrorEventCount = 0;

    MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();

    ds.setURL(BaseTestCase.dbUrl);

    this.cpds = ds;
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:20,代码来源:PooledConnectionRegressionTest.java

示例11: testBug4808

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入依赖的package包/类
/**
 * Tests fix for BUG#4808- Calling .close() twice on a PooledConnection
 * causes NPE.
 * 
 * @throws Exception
 *             if an error occurs.
 */
public void testBug4808() throws Exception {
    MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
    ds.setURL(BaseTestCase.dbUrl);
    PooledConnection closeMeTwice = ds.getPooledConnection();
    closeMeTwice.close();
    closeMeTwice.close();

}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:16,代码来源:DataSourceRegressionTest.java

示例12: testBug32101

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; //导入依赖的package包/类
/**
 * Tests fix for BUG#32101 - When using a connection from our ConnectionPoolDataSource,
 * some Connection.prepareStatement() methods would return null instead of
 * a prepared statement.
 * 
 * @throws Exception
 */
public void testBug32101() throws Exception {
    MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
    ds.setURL(BaseTestCase.dbUrl);
    PooledConnection pc = ds.getPooledConnection();
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1"));
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1", Statement.RETURN_GENERATED_KEYS));
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1", new int[0]));
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1", new String[0]));
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
    assertNotNull(
            pc.getConnection().prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT));
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:20,代码来源:DataSourceRegressionTest.java


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