Guest User

Untitled

a guest
Dec 17th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import ballerina/log;
  2. import ballerina/mysql;
  3.  
  4. //Create mysql client
  5. mysql:Client testDB = new({
  6. host: "localhost",
  7. port: 3306,
  8. name : "ballerinademo",
  9. username: "test",
  10. password: "test"
  11. });
  12.  
  13. //Create a record which matches the selected data
  14. type data record {
  15. int id;
  16. string name;
  17. };
  18.  
  19. public function main(string... args) {
  20. //Perform the select operation
  21. var ret = testDB->select("select id, name from employee where id = ?", data, 1);
  22. if (ret is table<data>) {
  23. //Iterate each row of the selected data
  24. foreach var row in ret {
  25. log:printInfo(row.name);
  26. }
  27. } else if (ret is error) {
  28. log:printInfo(<string>ret.detail().message);
  29. }
  30. //Stop the mysql client
  31. testDB.stop();
  32. }
Add Comment
Please, Sign In to add comment