我是芭蕾舞女演员的新手,并试图了解基本用法和功能。有没有什么简单的方法可以将 PostgreSQL 数据库与 Ballerina App 连接起来?
问问题
339 次
1 回答
2
您可以使用 ballerina jdbc 包来执行此操作。另请注意,您必须将 postgres jdbc驱动程序复制到 ${BALLERINA_HOME}/bre/lib。
以下是连接到 postgres 数据库并执行选择操作的示例。
import ballerina/jdbc;
import ballerina/io;
endpoint jdbc:Client testDB {
url: "jdbc:postgresql://localhost:5432/testdb3",
username: "postgres",
password: "123",
poolOptions: { maximumPoolSize: 1 }
};
type Customer record {
int id,
string name,
};
function main(string... args) {
table dt = check testDB->select("select id, name from Customers", Customer);
while (dt.hasNext()) {
Customer rs = check <Customer>dt.getNext();
io:println(rs.id);
io:println(rs.name);
}
testDB.stop();
}
请参阅此内容以获取有关 ballerina jdbc 包功能的完整示例。
于 2018-08-03T04:49:20.080 回答