未验证 提交 c93a24f2 编写于 作者: H huili 提交者: GitHub

Merge pull request #5052 from taosdata/zyyang-taosdata-patch-6

Update connector-java-ch.md
...@@ -339,9 +339,10 @@ conn.close(); ...@@ -339,9 +339,10 @@ conn.close();
config.setUsername("root"); config.setUsername("root");
config.setPassword("taosdata"); config.setPassword("taosdata");
// connection pool configurations // connection pool configurations
config.setMinimumIdle(3); //minimum number of idle connection config.setMinimumIdle(10); //minimum number of idle connection
config.setMaximumPoolSize(10); //maximum number of connection in the pool config.setMaximumPoolSize(10); //maximum number of connection in the pool
config.setConnectionTimeout(30000); //maximum wait milliseconds for get connection from pool config.setConnectionTimeout(30000); //maximum wait milliseconds for get connection from pool
config.setMaxLifetime(0); // maximum life time for each connection
config.setIdleTimeout(0); // max idle time for recycle idle connection config.setIdleTimeout(0); // max idle time for recycle idle connection
config.setConnectionTestQuery("select server_status()"); //validation query config.setConnectionTestQuery("select server_status()"); //validation query
...@@ -375,24 +376,22 @@ conn.close(); ...@@ -375,24 +376,22 @@ conn.close();
* 使用示例如下: * 使用示例如下:
```java ```java
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Properties properties = new Properties();
DruidDataSource dataSource = new DruidDataSource();
// jdbc properties // jdbc properties
properties.put("driverClassName","com.taosdata.jdbc.TSDBDriver"); dataSource.setDriverClassName("com.taosdata.jdbc.TSDBDriver");
properties.put("url","jdbc:TAOS://127.0.0.1:6030/log"); dataSource.setUrl(url);
properties.put("username","root"); dataSource.setUsername("root");
properties.put("password","taosdata"); dataSource.setPassword("taosdata");
// pool configurations // pool configurations
properties.put("maxActive","10"); //maximum number of connection in the pool dataSource.setInitialSize(10);
properties.put("initialSize","3"); //initial number of connection dataSource.setMinIdle(10);
properties.put("minIdle","3"); //minimum number of connection in the pool dataSource.setMaxActive(10);
properties.put("maxWait","30000"); //maximum wait milliseconds for get connection from pool dataSource.setMaxWait(30000);
properties.put("validationQuery","select server_status()"); //validation query dataSource.setValidationQuery("select server_status()");
//create druid datasource Connection connection = dataSource.getConnection(); // get connection
DataSource ds = DruidDataSourceFactory.createDataSource(properties);
Connection connection = ds.getConnection(); // get connection
Statement statement = connection.createStatement(); // get statement Statement statement = connection.createStatement(); // get statement
//query or insert //query or insert
// ... // ...
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册