Database Connectivity
Database Connectivity
calac41
HID_database_connectivity
For more information about how to set up connectivity to your database when creating your API, see Create your API.
You can connect to multiple databases in the same API or combine resources, build rules between databases, and access them by defining multiple databases. For example, you create an empty database and then connect your API to other databases. You can also connect to a new database using your current tools and then connect to that database when you create your API using API Creator.
API Creator update processing relies on database services for locking and transaction management. API Creator retrieval processing optimizes queries by leveraging the database engine's services, such as the index selection. The defined SQL joins determine how much API Creator can optimize the query.
You can manage your data source connections by adding, updating, and deleting them.
In this article:
Add a Connection to a Database
Each API includes a list of one or more registered databases and one or more SQL database locations. This list might include only the database connections that you established when you created your API.
Follow these steps:
- In the Create section, clickData Sources.The Data Sources page appears. A list of existing data source connections displays on the Connection tab.
- Above the list of data source connections, clickAdd.The Create Data Source window opens.
- Create the data source by completing the following fields, and then clickingAdd:Create data source usingThe category of data source. SelectJDBC data source.Values:
- JDBC data source.A JDBC data source for a JDBC driver thatCA Live API Creatorsupports.
- Managed data server.A data source connected to the selected managed data server.
- JNDI data source.A JDBC data source through a container's JNDI definition.
Data source typeSpecifies the type of data source that you want to use.Values:MySQL, Oracle, PostgreSQL, Salesforce, Derby, Apache HBase, SQLServer, AzureSQL, DB2 for z/OS, DB2 for LUW, SAP Netweaver, CSV Files, Cassandra, and TeradataDefault:MySQLFor more information about which data source to use, consult your database administrator or system administrator.Data source nameThe name for your data source connection. Enter a name that coordinates with your API definition.CA Live API Creatoruses this name as the file name for source code control management when you export the API.Unique:YesData source prefixThe prefix for your data source connection. Database prefixes help identify the database objects (for example, tables, views, and procedures). Resources, rules, and JavaScript reference multiple data sources using the database prefix. If you have more than one active database in your API, the prefix specifies the database thatCA Live API Creatorshould use, for instance, when defining rules and resources.References to entities (table or view), for example, in rules, resource definitions, and role permissions, include the database prefix.The database prefix is represented as text, so you can swap test/production databases.Maximum length:20 charactersCase Sensitive:YesBest Practice:Choose your database prefix name carefully. Consider using a memorable word, for example "demo" or "customers".Your JDBC data source is added. - Complete the following field, and then save your changes:NameThe name for your data source. This is theData source namethat you specified when you created the data source. You can modify the data source name.Unique:YesPrefixThe prefix for your data source connection. This is theData source prefixthat you specified when you created the data source. You can change the data source prefix.Maximum length:20 charactersCase Sensitive:YesChanging the data source prefix breaks rules and resources.For more information about how to rename your database prefix, see Integrate Multiple Databases.TitleThe description of your data source.Optional:YesTypeThe type of data source. This is the type that you specified when you created your data source.When you are creating your data source, this field is theData source typefield.Read-only:YesURLThe database-dependent URL that points to your data source. When you create an API and you connect to an empty database, the database name is appended to this URL.Examples:
- MySQL database URL example:jdbc:mysql://<server-name>[:port-number (default 3306)]/[database-name]
- Derby database URL example:jdbc:derby:C:\LAC\Jetty\projects\Market\MarketDB
- DB2 for LUW database URL example:jdbc:db2://<host>:<port>/<schema_name>
Database/Catalog nameThe database or catalog name that points to your schema on the database server.Case Sensitive:- Derby, DB2, Oracle, DB2 for zOS, DB2 for LUW:Lowercase is equivalent to uppercase. For example, foo, Foo, and FOO are all equivalent and are converted to uppercase (FOO). If the value uses mixed case, enclose the name in double quotes ("), for example "Foo". You can enclose the value with the correct case and unusual characters using double-quotes (").
- Example:(For DB2 for LUW) LAC_DEMO_EBSDEV
- PostgreSQL:Uppercase is equivalent to lowercase. For example, foo, Foo and FOO are all equivalent and are converted to lowercase (foo). If the value uses mixed case, enclose the name in double quotes, for example "Foo". You can enclose the value with the correct case and unusual characters using double-quotes (").
- SQL Server:Case-insensitive but case-remembering. Enter the value exactly as it is spelled, using the correct case. You can enclose the value with the correct case and unusual characters using double-quotes (").
- MySQL:The name's behavior depends on the the underlying operating system and configuration settings. You can quote the value when required by MySQL, enclose the value with the correct case, and enclose unusual characters using back-ticks (`).
User nameYour assigned user name in the database. You use this user name inCA Live API Creatorto connect to the database.Case Sensitive:- Derby, DB2, Oracle, DB2 for zOS, DB2 for LUW:Lowercase is equivalent to uppercase. For example, foo, Foo, and FOO are all equivalent and are converted to uppercase (FOO). If the value uses mixed case, enclose the name in double quotes ("), for example "Foo". You can enclose the value with the correct case and unusual characters using double-quotes (").
- Example:DBADMIN
- PostgreSQL:Uppercase is equivalent to lowercase. For example, foo, Foo and FOO are all equivalent and are converted to lowercase (foo). If the value uses mixed case, enclose the name in double quotes, for example "Foo". You can enclose the value with the correct case and unusual characters using double-quotes (").
- SQL Server:Case-insensitive but case-remembering. Enter the value exactly as it is spelled, using the correct case. You can enclose the value with the correct case and unusual characters using double-quotes (").
- MySQL:The name's behavior depends on the the underlying operating system and configuration settings. You can quote the value when required by MySQL, enclose the value with the correct case, and enclose unusual characters using back-ticks (`).
PasswordThe password for the database. This is the password for the user that accesses this data source.Maximum connectionsThe maximum number of connectionsCA Live API Creatoruses to create a pool of database connections. Each request accessing this data source retrieves a connection from the pool, uses the connection, and then returns the connection to the pool.Default:20If you change this value, then you must apply the changes to connection pooling by restarting API Server.ActiveSelect this checkbox to activate this data source connection, to use this data source as the current database for your API, and to test the connection to the database. IfCA Live API Creatoris unable to connect to the database successfully,CA Live API Creatorclears this checkbox and marks the database as inactive.Default:ClearedLog errorsSelect this checkbox if you want to record database-level errors for this data source in the log.Default:ClearedSelecting this checkbox can impact performance.Schema is editableSelect this checkbox to allow users with the appropriate credentials to edit the schema for this database.Default:Cleared - ClickTest Connection.API Creator verifies the connection to this database.CA Live API Creatormust successfully connect to the database before you can use this database as the current database for your API.
The database connection is added.
: Recent versions of MySQL might require that you connect to MySQL using Secure Sockets Layer (SSL). The following error message indicates this requirement:
javax.net.ssl.SSLException: Unsupported record version Unknown-0.0
You can avoid this MySQL SSL exception.
For more information about how to avoid this exception, see Troubleshooting.
Debug Database Issues
You can debug database issues using the error log.
Follow these steps:
- In the Create section, clickData Sources.The Connection tab displays by default.
- ClickError log.The Error log page displays.
View your Schema
When you connect to a database, API Creator reads your database schema. API Creator references the database objects and determines the names (table names, view names, column names, foreign key names, and procedures) from the database or catalog. API Creator creates endpoints, or resources, and the JavaScript object model using the database schema.
The schema page shows your tables, views, and stored procedures.
Follow these steps:
- With your API open, in the Create section, clickSchema.The Tables tab displays by default.
- Complete one of the following:
- To view your tables, click theTablestab.
- To view your views, click theViewstab.
- To view your stored procedures, database functions, and packages, click theProcedurestab.
CA Live API Creatorescapes the periods (.) found in table, stored procedure, and function names by appending a tilde (~).Best practice:Call endpoints by using thehrefattribute that is in the@metadatasection of a JSON response.
Traverse Rules
- With your API open, in the Create section, clickSchema.The Tables tab displays by default.
- Double-click the rule in the Rules list.The rule opens.
Data Source Best Practices
We recommend explicit associations between a child entity (table or view) and its parent entity. Define foreign keys by way of validations, including a validation name. You can define virtual relationships across schemas by defining relationships between databases.
For more information:
- About how to define foreign keys by way of validations, see Validation Rule Type.
- About how to define relationships between databases, see Manage Relationships.