Oracle database version used: Oracle-xe-11g (Follow these instructions explained here to install Oracle-xe-11g with Docker).
This Sample is written using ballerinax/jdbc module. Before running this sample you need to copy the Oracle JDBC driver jar into $BALLERINA_HOME/bre/lib.
First, create the table using the following command:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE oracledb(id NUMBER, byte_array RAW(10)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ballerina/io; | |
import ballerinax/jdbc; | |
import ballerina/sql; | |
jdbc:Client testDB = new({ | |
url: "jdbc:oracle:thin:@localhost:49161:xe", | |
username: "system", | |
password: "oracle", | |
poolOptions: { maximumPoolSize: 1 } | |
}); | |
byte[] bitVal2 = [1, 2]; | |
public function main() { | |
var dt1 = testDB->update("INSERT INTO oracledb(id, byte_array) VALUES (1, ?)", bitVal2); | |
handleUpdate(dt1, "Update oracledb table"); | |
} | |
function handleUpdate(sql:UpdateResult|error returned, string message) { | |
if (returned is sql:UpdateResult) { | |
io:println(message + " status: " + returned.updatedRowCount); | |
} else { | |
io:println(message + " failed: " + <string>returned.detail().message); | |
} | |
} |
ballerina run insertByteArray.bal
Output:
Update oracledb table status: 1
No comments:
Post a Comment