當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。