I have a SQL Server database table with this structure:
CREATE TABLE json_file_table
(
file_id VARCHAR(50) PRIMARY KEY,
json_value VARBINARY(MAX)
);
How to write a SQL query to insert value into the database and bind values to that query in Ballerina?
2
Answers
Assuming you are using
NVARCHAR
as the column type forjson_value
, you can use the toJsonString method to convert JSON to a string and store it as a string.}
First you need to convert your json value into a
byte[]
Then you needs to create a
sql:varBinaryValue
instance using above bytes.sql:VarBinaryValue varBinaryValue = new sql:VarBinaryValue(b)
.Then use that varBinaryValue in your sql query.