Page tree
Skip to end of metadata
Go to start of metadata

API Overview

The pjs.connect() API creates a connection to a database.

If SQL API are used without an established connection, an attempt to connect to the default database ("*LOCAL" for IBM i ) is automatically initiated.

Important!

This API requires the Profound.js Connector module.

Parameters

For IBM i connections:

  1. database name (18 characters max)
    You can use "*LOCAL" to connect to the local database.
  2. username (optional, 10 characters max)
    Must be from a user profile. This username is used to connect to the database
  3. password (optional, 128 characters max)
    Must be the password of the user profile being used to connect with the database.

For other database connections, the connection parameters must match the connection config format of the database driver's corresponding NPM package. If no parameters are specified, the default connectionDetails settings are used.

Exception Handling

SQL diagnostics are reported in the SQLCA:

https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/db2/rbafzfielddescsqlca.htm

SQLCA fields are defined in Profound.js programs with the names in lowercase. sqlcode will be set to zero if execution was successful.

Examples

IBM i Connection Example
pjs.connect("*LOCAL");

  

MySQL Connection Example
pjs.connect({
  user: 'testuser',
  password: 'testpwd',
  server: 'localhost',
  database: 'testdb'
});