全部产品
云市场

Druid

更新时间:2019-12-24 16:14:25

本文介绍如何在Druid中连接DLA。

  1. package demo;
  2. import com.alibaba.druid.pool.DruidDataSource;
  3. import java.sql.Connection;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. public class DLAJavaDemo {
  8. public static void main(String[] args) throws SQLException {
  9. DruidDataSource dds = new DruidDataSource();
  10. dds.setUrl("jdbc:mysql://<DLA Endpoint前缀>.<DLA Region,例如cn-beijing>.datalakeanalytics.aliyuncs.com:10000");
  11. dds.setUsername("<DLA账号>");
  12. dds.setPassword("<DLA账号密码>");
  13. dds.setMinIdle(1);
  14. dds.setInitialSize(1);
  15. dds.setMaxActive(10);
  16. dds.setXxx()
  17. try (Connection c = dds.getConnection()) {
  18. try (Statement s = c.createStatement()) {
  19. try (ResultSet rs = s.executeQuery("select * from your_dla_schema.your_dla_table")) {
  20. while (rs.next()) {
  21. System.out.println(rs.getObject(1));
  22. }
  23. }
  24. }
  25. }
  26. }
  27. }

更多配置请参见DruidDataSource