Код: Выделить всё
import ballerina/io;
// import ballerina/http;
import ballerinax/mysql;
import ballerina/sql;
configurable string dbHost = ?;
configurable int dbPort = ?;
configurable string dbUser = ?;
configurable string dbPassword = ?;
configurable string dbName = ?;
type User record {
int userId;
string email;
string password;
string createdAt;
string updatedAt;
};
mysql:Client|sql:Error dbClientResult = check new (
user = dbUser,
password = dbPassword,
database = dbName,
host = dbHost,
port = dbPort
);
final mysql:Client dbClient = check dbClientResult;
public function main() returns error? {
io:println("MySQL Connected to " + dbName);
return;
}
isolated function insertUser(mysql:Client dbClient, User entry) returns sql:ExecutionResult|error {
User {userId, email, password, createdAt, updatedAt} = entry;
sql:ParameterizedQuery insertQuery = `INSERT INTO users (id, email, password, createdAt, updatedAt)
VALUES (${userId}, ${email}, ${password}, ${createdAt}, ${updatedAt})`;
return dbClient->execute(insertQuery);
}
Код: Выделить всё
error: Error while loading database driver. This may be because the database driver path is not configured correctly in the `Ballerina.toml` file or provided database driver version is not supported by the connector
Код: Выделить всё
[mysql]
driverPath = "libs\\mysql-connector-java-8.0.26.jar"
- Балерина = 2201.12.10
- MySQL = 1.16.1
Подробнее здесь: https://stackoverflow.com/questions/798 ... ase-driver
Мобильная версия