全部產品
Search
文件中心

:Druid

更新時間:Jul 06, 2024

本文介紹如何在Druid中串連DLA。

package demo;
import com.alibaba.druid.pool.DruidDataSource;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DLAJavaDemo {
    public static void main(String[] args) throws SQLException {
        DruidDataSource dds = new DruidDataSource();
        dds.setUrl("jdbc:mysql://<DLA Endpoint首碼>.<DLA Region,例如cn-beijing>.datalakeanalytics.aliyuncs.com:10000");
        dds.setUsername("<DLA帳號>");
        dds.setPassword("<DLA帳號密碼>");
        dds.setMinIdle(1);
        dds.setInitialSize(1);
        dds.setMaxActive(10);
        dds.setXxx()
        try (Connection c = dds.getConnection()) {
            try (Statement s = c.createStatement()) {
                try (ResultSet rs = s.executeQuery("select * from your_dla_schema.your_dla_table")) {
                    while (rs.next()) {
                        System.out.println(rs.getObject(1));
                    }
                }
            }
        }
    }
}
        

更多配置請參見DruidDataSource