本文介绍如何在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。