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


Java DruidDataSource.getConnection方法代码示例

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


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

示例1: testJDBC

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Test
public void testJDBC() throws Exception {
    Properties properties = new Properties();
    properties.put("url", "jdbc:elasticsearch://127.0.0.1:9300/" + TestsConstants.TEST_INDEX);
    DruidDataSource dds = (DruidDataSource) ElasticSearchDruidDataSourceFactory.createDataSource(properties);
    Connection connection = dds.getConnection();
    PreparedStatement ps = connection.prepareStatement("SELECT  gender,lastname,age from  " + TestsConstants.TEST_INDEX + " where lastname='Heath'");
    ResultSet resultSet = ps.executeQuery();
    List<String> result = new ArrayList<String>();
    while (resultSet.next()) {
        result.add(resultSet.getString("lastname") + "," + resultSet.getInt("age") + "," + resultSet.getString("gender"));
    }

    ps.close();
    connection.close();
    dds.close();

    Assert.assertTrue(result.size()==1);
    Assert.assertTrue(result.get(0).equals("Heath,39,F"));
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:21,代码来源:JDBCTests.java

示例2: testGetDataSourceByMap

import com.alibaba.druid.pool.DruidDataSource; //导入方法依赖的package包/类
@Test
public void testGetDataSourceByMap() throws Exception {
    Map<String, String> config = new HashMap<>();
    config.put("driverClassName", "com.mysql.jdbc.Driver");
    config.put("url", "jdbc:mysql://123.206.133.24:4858/minsx?useUnicode=true&characterEncoding=utf-8&autoReconnect=true");
    config.put("username", "wssswcom");
    config.put("password", "Ss123456");
    config.put("initialSize", "5");
    config.put("minIdle", "5");
    config.put("maxActive", "50");
    config.put("maxWait", "60000");
    config.put("timeBetweenEvictionRunsMillis", "60000");
    config.put("minEvictableIdleTimeMillis", "300000");
    config.put("multiStatementAllow", "true");
    config.put("validationQuery", "SELECT 1");
    config.put("testWhileIdle", "true");
    config.put("testOnBorrow", "false");
    config.put("testOnReturn", "false");
    config.put("poolPreparedStatements", "false");
    config.put("maxPoolPreparedStatementPerConnectionSize", "20");
    DruidDataSource dataSource = DataSourceFactory.createDataSource("minsx", config);
    Connection connection = dataSource.getConnection();
    connection.close();

}
 
开发者ID:MinsxCloud,项目名称:minsx-java-example,代码行数:26,代码来源:MainTest.java


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