Updated on 2023-02-28 GMT+08:00

DataSourceClient

Path

com.roma.apic.livedata.client.v1.DataSourceClient

Description

This class is used to connect to data sources and run SQL statements, stored procedures, or NoSQL query statements.

Example

SQL data source example:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
importClass(com.roma.apic.livedata.client.v1.DataSourceClient);
importClass(com.roma.apic.livedata.config.v1.DataSourceConfig);
function execute(data){
    var config = new DataSourceConfig()
    config.setType("mysql")
    config.setUrl("jdbc:mysql://127.0.0.1:3306/db?allowPublicKeyRetrieval=true")
    config.setUser("username")
    config.setPassword("password")
    var ds = new DataSourceClient(config)
    return ds.execute("SELECT * FROM person where name = ? and age = ?", "Tom", 20);
}

NoSQL data source example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
importClass(com.roma.apic.livedata.client.v1.DataSourceClient);
importClass(com.roma.apic.livedata.config.v1.DataSourceConfig);
function execute(data){
    var config = new DataSourceConfig()
    config.setType("redis")
    config.setUrl("127.0.0.1:6379")
    config.setPassword("password")
    var ds = new DataSourceClient(config)
    return ds.execute("GET key");
}

Constructor Details

public DataSourceClient(DataSourceConfig config)

Import the data source configuration and construct a data source connector.

Method List

Returned Type

Method and Description

Object

execute(String sql, Object... prepareValue)

Run SQL statements, stored procedures, or NoSQL query statements.

Method Details

  • public Object execute(String sql, Object... prepareValue)

    Run SQL statements, stored procedures, or NoSQL query statements.

    Input Parameter

    • prepareValue: This parameter is valid only in SQL statements and is used to replace "?" in SQL statements to prevent SQL injection.

    Returns

    Statement execution results

    Throws

    Exception