JDBC Serializer

Use JDBCSerializerarrow-up-right to serialize Java JDBC ResultSetarrow-up-right object to the Candid payload of type RECORD.

A fully functional example using JDBCSerializer can be found herearrow-up-right.

This example uses Motoko to call the canister main.moarrow-up-right. The canister uses complex type CreditCheck.

main.mo
  // Credit Check
  public type Credit = {
    ssn: Text;   
    rating: Int32;
  };

The canister has 1 method: apply and setCredit.

main.mo
    public shared (msg) func setCredit(input : Credit){
        Debug.print("Credit Check for ssn " #input.ssn);
    };

The example uses the data from embedded Apache Derbyarrow-up-right SQL database as an input. Database table is reinitialized every time the sample runs.

Main.java
Statement statement = connection.createStatement();
String sql = "CREATE TABLE data (ssn VARCHAR(11) PRIMARY KEY,rating INT)";
statement.execute(sql);
sql = "INSERT INTO data VALUES ('111-11-1111',550)";
statement.execute(sql);
sql = "INSERT INTO data VALUES ('222-22-2222',650)";
statement.execute(sql);
sql = "INSERT INTO data VALUES ('333-33-3333',750)";
statement.execute(sql);

Execute JDBC PreparedStatementarrow-up-right to get ResultSet data from the database.

The Serializer input is the variable of type ResultSetarrow-up-right. To serialize individual row from ResultSet to Candid RECORD use function array with false value. Otherwise the result will be Candid VEC type, wrapping Candid RECORD items.

Use UpdateBuilder, QueryBuilder or Raw Methods to call the Canister.

Last updated