Updated on 2024-03-04 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:
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);
}
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("oracle")
  config.setUrl("jdbc:oracle:thin:@127.0.0.1:1521/db")
  config.setUser("username")
  config.setPassword("password")
  var ds = new DataSourceClient(config)
  return ds.execute("select table_name from user_tables");
}

NoSQL data source example:

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