I am trying to setup a simple JDBC client to talk with a database in Ballerina.
However the "compile" ( VSCode ) error that is shown says:
invalid remote method call: expected a client object, but found (ballerinax/java.jdbc:1.7.0:Client|ballerina/sql:1.7.1:Error)(BCE2421)
Here is my full source code:
import ballerinax/java.jdbc;
import ballerina/sql;
public type User record {|
int id?;
string name;
string username;
string email;
int? client_id;
|};
configurable string USER = ?;
configurable string PASSWORD = ?;
configurable string HOST = ?;
configurable int PORT = ?;
configurable string DATABASE = ?;
final jdbc:Client|sql:Error dbClient = new (
url="", user=USER, password=PASSWORD
);
isolated function getUser(int id) returns User|error {
sql:ParameterizedQuery query = `select * from users where ${id} = ?`;
User user = dbClient->query(query); // <--- THIS IS THE LINE THAT SHOWS ERROR
return user;
}