Description

A JDBC Service Function is used to interface with Java Database Connectivity (JDBC) and Open Database Connectivity (ODBC) data sources. Typically these data sources are relational databases that are queried using Structured Query Language (SQL.)

JDBC Services require a JDBC driver. There are commercial drivers available for all major databases and free drivers available for most. See JDBC Drivers for a list. ODBC data sources are reachable via a JDBC-ODBC bridge driver, which can communicate

with the relevant ODBC driver. Sun provides a standard JDBC-ODBC bridge driver. ODBC drivers are available for all major databases. In general a JDBC driver provides better performance than using an ODBC driver and the JDBC-ODBC Bridge.

When accessing a remote database, JDBC uses the Internet's file addressing scheme. A file name looks much like a Web page address (or Uniform Resource Locator). For example a Java SQL statement might identify the database as: jdbc:odbc://www.somewhere.com:400/databasefile.

Connections can be made either via a database driver and URL, or via JNDI. Using JNDI allows connection pooling if your application server supports this.

To set up a JDBC Service

  1. Make sure the JDBC driver you want to use is available on your servlet engine's CLASSPATH.

  2. From the Application Manager menu either:

  3. Click on the New JDBC Services button  in the toolbar.

  4. Click on the Edit|New JDBC service menu item.

  5. Right-click on the Services node in the Application Explorer and select New JDBC service in the context menu.

A Service Function is added to the list of Services with the default name of JDBCSERVICE1.

The following JDBC Service window will open:

  1. On the Request tab, enter the class name of the driver you are using.
    For example:com.mysql.jdbc.Driver.

  2. Enter the URL used to connect to the database.
    For example: jdbc:mysql://${db.server.name}/ros?user=test&password=test.
    The driver class name, and URL syntax will be specific to the database and driver you are using. The username and password may also be entered separately from the URL. Check the database and driver documentation for details.

  3. Enter a SQL statement for the query you would like to use. Use ${ } notation for any substitutable parameters. You may want to try out the query directly against the database first to make sure the SQL syntax is correct.

  4. Switch to the Test tab. This will automatically check for parameters and add them to a list so you can enter test values.

  5. Click the Test button.

If there is a problem with your setup, or with your SQL query, then appropriate messages will be displayed. Once your service is working you can fine tune the SQL, TEMPLATE and return messages and then re-test.

Tick the Dynamic SQL option if SQL is dynamically passed in from the client. Use this feature with care because different queries may result in record sets not compatible with defined template.

The Request Tab

The Request tab specifies how the JDBC service is executed.

  1. Set the Connection Settings box. These control how the Presentation Server will connect to the back-end application. Either URL and DRIVER, or a JNDI name must be specified.

  2. Tick the Dynamic SQL option if SQL is dynamically passed in from the client. Use this feature with care because different queries may result in record sets not compatible with defined template.

  3. In SQL field enter the SQL query to execute. Property references ${ } can be used. They will be substituted before each execution of the service.

The Response Tab

The Response tab is used to define what type of data to expect from the Service Function.

Enhanced Response Processing option

Check this box if you want to use Enhanced JDBC Response Data Processing. This feature allows you to build more flexible output xml data, including multi-level xml structure and references to properties.

Remove attribute if no value option

When JDBC Service Functions process result data, some attributes may contain no value. Check this box if you want to remove all attributes with no value.

Template field

This field is used to map data returned from SELECT queries into XML. This is optional, if you left blank for a SELECT statement, a default template will be used. For each row returned, each attribute value within the template is replaced by the value of the database column specified.

Generate Template button

This button generates a sample template. This is used for SELECT statements to convert the data returned into XML format. You can customize the generated template if necessary, or write your own one. Note that you must have a connection set up first, and a SELECT statement entered in the SQL setting.

Setting the "When service is used for initial data request" frame

Custom Initial Timestamp

Please note: This only applies to XML Service Functions.

Check this box if you want the Timestamp to be extracted from a customized location. If this option is selected you can set the Element and Attribute for locating timestamp information. By default Timestamp are extracted from a Timestamp Attribute on the root element of the XML returned by the Service.

System Generated Timestamp

Please note: This option is useful when the return data doesn't contain Timestamp information. However, if you use MASTER-MASTER cluster configuration, data might be lost in failover situation, because the timestamp value for a data block can be different on two Presentation Servers.

Please also note: APS uses Java currentTimeMillis() to set the timestamp. Although its precision is down to 1 ms, the problem is that default timing systems on the native platforms are, in general, of low resolution. The currentTimeMillis is updated every 10ms ~ 16 ms. Therefore it is possible that 2 updates arrive in order but end up in the same millisecond. Check this box if you want the Presentation Server to use system clock for the Timestamp value.

Element (XPath query)

Set this field to an XPath statement pointing to the element containing Timestamp information. By default the Presentation Server continues to find Timestamp information from root element. If more than one element matches, only the first element is used.

Attribute

Specify the attribute name containing the Timestamp info or TEXT() to indicate that the element's text contains the timestamp. By default the Presentation Server finds Timestamp information from Timestamp default attribute.

Type

Specify whether the Timestamp field is to be read as a Date/Time or as an Integer. By default the Type is set to Integer.

Format

Specify the Format used to parse the Timestamp from the specified Element and Attribute. For a Date/Time this should be a format recognized by java.text.SimpleDateFormat. For an Integer this should be a format recognized by java.text.DecimalFormat. By default if the Type is set to Integer then the Timestamp Attribute is read as an Integer.

Create new transformer

Check this box if you want this service to create a new transformer instance every time it does the transformation. By default this option is set to false.

The Acknowledgement Tab

The Acknowledgment tab is used to define how the success or failure of the Service Function is communicated to the client.

  1. From the On success Source drop-down menu, choose one of the following:

  2. If you have selected DEFINE, enter in the Text field the success message to send to the AltioLive client when a service succeed.

  3. From the On failure Source drop-down menu, choose one of the following:

  4. If you have selected DEFINE, enter in the Text field the fail message to send to the AltioLive client when a service failed.

The Test Tab

The Test tab allows a JDBC Service to be tested. Whatever operation you test will be executed on your back-end application. You may need to reset values in your database after testing.

Please note: this is not a simulated test.

  1. In the Name cell enter the name of parameters being used. This corresponds to a parameter in the SQL statement.

  2. In the Test value cell enter a value to test the service.

  3. Click the Test Service button. This displays the results of using the parameters specified in the table. You will be informed whether the test was successful or not, and if not, error messages will be displayed to help you deduce what went wrong.

  4. If a WARNING message No Datakey is defined for element NAME_ELEMENT is displayed, you can click on the Extract Datakeys button in order to create a datakey for this element.

For more information: See the Setting up Datakeys section.

Examples of JDBC Service Functions setting

First Example

This example shows how a simple template is constructed:

Service Name:

MYFUNCTION

Request tab

Connection Settings:

Driver and URL

Driver:

com.mysql.jdbc.Driver

URL:

jdbc:mysql://localhost:3306/ros

User

test

Password

test

SQL:

SELECT THING FROM STUFF

Response tab

Template:

<MY FUNCTION>
<STUFF THING='datareturned/'>
</MY FUNCTION>

 

Second Example

This example updates the SALE_ITEM table, changing the PORT column. Test values have also been included here.

Service Name:

EXISTING_ITEM_UPDATE

Request tab

Connection Settings:

Driver and URL

Driver:

com.mysql.jdbc.Driver

URL:

jdbc:mysql://localhost:3306/ros?user=test&password=test

SQL:

UPDATE SALE_ITEM SET PORT=${client.PORT} WHERE PROD_ID=${client.PROD_ID}

Response tab

Template:

none - this function does not select data

Acknowledgement tab

On success: Source

Define

Text

Data has been updated

On failure: Source:

Define

Text

Error: data has not been updated

Test tab

Name

PORT

Value

Rotterdam

Name

PROD_ID

Value

ID43

 

Third Example

Service name:

DEL_SEVENTEEN

Request tab

Connection settings:

Driver and URL

Driver:

com.mysql.jdbc.Driver

URL:

jdbc:mysql://localhost:3306/ros?user=test&password=test

SQL:

DELETE FROM ITEM WHERE ITEM_ID='17'

Response tab

Template:

none - this function does not select data

Acknowledgement tab

On success: Source:

Define

Text:

Data has been deleted

On failure: Source

Define

Text:

Error: data has not been deleted

 

Fourth Example

This example uses a JOIN statement as part of the SELECT, and has a more complicated Template:

Service name:

GET_FORSALE

Request tab

Connection settings:

Driver and URL

Driver:

com.mysql.jdbc.Driver

URL:

jdbc:mysql://localhost:3306/ros?user=test&password=test

SQL:

SELECT S.QTY AS S_QTY, S.EXP_DATE AS S_EXP_DATE, S.PROD_ID AS S_PROD_ID, S.PROD AS S_PROD, S.SALE_ID, S.CTRY AS S_CTRY, S.PORT AS S_PORT, S.CURRENCY AS S_CURRENCY, SELLER_ID, ITEM_ID, CONTROL, S.PRICE AS S_PRICE, S.COMMENT AS S_COMMENT,

        S.SH_TRMS AS S_SH_TRMS, S.AL_ACTION AS S_AL_ACTION, CONVERT(INT, S.TIMESTAMP) AS S_TS, B.QTY AS B_QTY, BIDDER_ID,

        B.PROD_ID AS B_PROD_ID, B.PROD AS B_PROD, B.CTRY AS B_CTRY, B.PORT AS B_PORT, B.CURRENCY AS B_CURRENCY, B.EXP_DATE AS B_EXP_DATE, B.PRICE AS B_PRICE, B.COMMENT AS B_COMMENT, BID_ID, B.SH_TRMS AS B_SH_TRMS, B.AL_ACTION AS B_AL_ACTION,

        CONVERT(INT, B.TIMESTAMP) AS B_TS FROM sale_item S LEFT OUTER JOIN bid B ON B.SALE_ID = S.SALE_ID'

Response tab

Template:

<FOR_SALE>

<SALE_ITEM QTY='S_QTY' EXP_DATE='S_EXP_DATE' PROD_ID='S_PROD_ID' PROD='S_PROD' SALE_ID='SALE_ID' CTRY='S_CTRY' PORT='S_PORT' CURRENCY='S_CURRENCY' SELLER_ID='SELLER_ID' ITEM_ID='ITEM_ID' CONTROL='CONTROL' PRICE='S_PRICE' COMMENT='S_COMMENT' SH_TRMS='S_SH_TRMS' TIMESTAMP='S_TS'>;

<BID QTY='B_QTY' BIDDER_ID='BIDDER_ID' PROD_ID='B_PROD_ID' PROD='B_PROD' CTRY='B_CTRY' PORT='B_PORT' CURRENCY='B_CURRENCY' EXP_DATE='B_EXP_DATE' PRICE='B_PRICE' COMMENT='B_COMMENT' BID_ID='BID_ID' SH_TRMS='B_SH_TRMS' AL_ACTION='B_AL_ACTION' TIMESTAMP='B_TS'/>

</SALE_ITEM>

</FOR_SALE>

Acknowledgement tab

On success: Source:

NONE

On failure: Source

Define

Text:

Error: no data selected

 

See also:

JDBC Services Troubleshooting, Enhanced JDBC Response Data Processing, Cache JDBC ResultSet, Offline , Set up Service Functions, Set up Datapools, Server request, Property References