Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ballerina/log;
- import ballerina/mysql;
- //Create mysql client
- mysql:Client testDB = new({
- host: "localhost",
- port: 3306,
- name : "ballerinademo",
- username: "test",
- password: "test"
- });
- //Create a record which matches the selected data
- type data record {
- int id;
- string name;
- };
- public function main(string... args) {
- //Perform the select operation
- var ret = testDB->select("select id, name from employee where id = ?", data, 1);
- if (ret is table<data>) {
- //Iterate each row of the selected data
- foreach var row in ret {
- log:printInfo(row.name);
- }
- } else if (ret is error) {
- log:printInfo(<string>ret.detail().message);
- }
- //Stop the mysql client
- testDB.stop();
- }
Add Comment
Please, Sign In to add comment