Constructing DBConnection

The DolphinDB Java API implements interactions by constructing connection objects to the DolphinDB server. The following introduces two methods for constructing DBConnection and provides their parameters and usage examples.

Constructor

Default Constructor

Create a DBConnection object with default constructor. See the Parameters Description in the next section Parameterized Constructor for their defaults.

DBConnection dbConnection = new DBConnection();

Parameterized Constructor

Create a DBConnection object with parameterized constructor. Specify the connection parameters as appropriate:

DBConnection(boolean asynchronousTask, boolean useSSL, boolean compress, boolean usePython, boolean isUrgent, SqlStdEnum sqlStd)

Parameters

  • asynchronousTask (optional, default false): Whether to execute tasks asynchronously. If it is set to true, the Java API can only execute DolphinDB scripts and functions without returning results, which is recommended for asynchronous writes.

  • useSSL (optional, default false): Whether to use SSL connection. If SSL is used, enableHTTPS=true must be configured for the server.

  • compress (optional, default false): Whether to compress data.

  • usePython (optional, default false): Whether to enable Python parser.

  • isUrgent (optional, default false): Whether the task is marked as urgent. If it is set to true, the urgent task will be executed even when the server is busy.

  • sqlStd (optional, default SqlStdEnum.DolphinDB): An enum specifying the syntax to parse input SQL scripts. Three parsing syntaxes are supported (since version 1.30.22.1): DolphinDB (default), Oracle, and MySQL. Users can specify this parameter by filling in the enumeration such as SqlStdEnum.DolphinDB.

Examples

Create a DBConnection object that enables asynchronous tasks and SSL connection, and uses Oracle syntax for SQL parsing.
DBConnection conn = new DBConnection(true, true, false, false, SqlStdEnum.Oracle);

Methods

Method

Description

DBConnection([asynchronousTask, useSSL, compress, usePython, isUrgent, sqlStd]) Construct a connection object
connect(host, port, [timeout, username, password, initialScript, enableHighAvailability, highAvailabilitySites, reconnect, enableLoadBalance])) Connect the session to DolphinDB server
login(username,password,enableEncryption) Log in to DolphinDB server
run(script)/tryRun(script) Run script on DolphinDB server
run(functionName,args)/tryRun(functionName,args) Call a function on DolphinDB server
upload(variableObjectMap) Upload local data to DolphinDB server
setLoadBalance(loadBalance) Enable/Disable load balancing when high availability is enabled
isBusy() Check if the current session is busy
close() Close the current session