1

I started an intership last week and I will implement some APIs with Ballerina. For learning purposes I have created (based on the JDBC Client CRUD Operations Example on the Ballerina website) a DB client with some sample queries.

Here is some example code:

jdbc:Client testDB = new ({
  url: "jdbc:mysql://localhost:3306/testDB?useLegacyDatetimeCode=false&serverTimezone=Europe/Vienna",
  username: "testUser",
  password: "password"
});

function db_getAllStudents() returns json {
  var result = testDB->select("SELECT * FROM student;", Student);
  if (result is table<record {}>) {
     json jsonStudents = jsonutils:fromTable(result);
     return jsonStudents;
  }
}

When I run the code everything works without any problems.

But I get some warnings that the usage of jdbc:Client and the select function is deprecated:

warning: dsa/service:0.1.0::DBOperations.bal:6:1: usage of construct 'jdbc:Client' is deprecated
warning: dsa/service:0.1.0::DBOperations.bal:18:18: usage of construct 'testDB.select(SELECT * FROM 
student;, Student)' is deprecated

Is there an alternative/newer construct to create a DB connection or to make select queries? I searched the official documentation but I could not find anything.

Dokksen
  • 372
  • 1
  • 4
  • 17

1 Answers1

1

This was recently discussed in Ballerina Slack channel.

WSO2 in currently rewriting JDBC connector. The rewrite will be available in the next major release (GA Jan 2021). Because the current JDBC connector will be replaced, WSO2 decided to deprecate JDBC connector implementation available in the current major release (i.e. 1.2).

Now we're in a weird situation that there is no Ballerina release with non-deprecated JDBC connector. In a retrospective WSO2 considers this is a mistake and in the next patch release (1.2.5) the deprecation status will be removed.

So it's safe to use the code in your post. The warnings will disappear in 1.2.5 (that should be available very soon).

user272735
  • 10,473
  • 9
  • 65
  • 96