DataDirect Test™ TutorialThis DataDirect Test tutorial explains how to use the most important features of DataDirect Test (and the JDBC API) and assumes that you can connect to a database with the standard available demo table or fine-tune the sample SQL statements shown in this example as appropriate for your environment.NOTE: The step-by-step examples used in this tutorial do not show typical clean-up routines (for example, closing result sets and connections). These steps have been omitted to simplify the examples. Do not forget to add these steps when you use equivalent code in your applications.install_dir/testforjdbc/Config.txtwhere install_dir is your product installation directory.The DataDirect Test configuration file can be edited as appropriate for your environment using any text editor. All parameters are configurable, but the most commonly configured parameters are:
A list of comma-separated JDBC URLs. The first item in the list appears as the default in the database selection window. You can use one of these URLs as a template when you make a JDBC connection. The default Config.txt file contains example URLs for most databases. Set to com.sun.jndi.fscontext.RefFSContextFactory if you are using file system data sources, or com.sun.jndi.ldap.LdapCtxFactory if you are using LDAP. The location of the .bindings file if you are using file system data sources, or your LDAP Provider URL if you are using LDAP. A list of comma-separated JDBC data sources. The first item in the list appears as the default in the data source selection window.To connect using a data source, DataDirect Test needs to access a JNDI data store to persist the data source information. By default, DataDirect Test is configured to use the JNDI File System Service Provider to persist the data source. To download the JNDI File System Service Provider, go to:Make sure that the fscontext.jar and providerutil.jar files from the download are on your classpath.
■ As a Java application on Windows—Run the testforjdbc.bat file located in the testforjdbc subdirectory of your product installation directory.On Windows 9x and Me, double-clicking testforjdbc.bat opens a DOS window and displays the error "Out of environment space." To prevent this, use the following procedure:
a After installing the product, locate the testforjdbc.bat file in the testforjdbc subdirectory in the installation directory.
b Right-click testforjdbc.bat and select Properties. After the properties display, select the Memory tab.
c On the Memory tab, locate the Initial environment setting. From this drop-down list, select 1024. Then, select the Protected check box. Click OK. A testforjdbc shortcut is created in the same directory with testforjdbc.bat.
d Double-click either testforjdbc.bat or the testforjdbc shortcut. DataDirect Test will open normally without generating the error.NOTE: Do not delete the testforjdbc shortcut; the 1024 environment setting will be lost if the shortcut is deleted.
■ As a Java application on Linux/UNIX—Run the testforjdbc.sh shell script located in the testforjdbc subdirectory in the installation directory.
■ In the JDBC/Database Output scroll box, a report indicating whether the last action succeeded or failed.TIP: DataDirect Test windows contain two Concatenate check boxes. Select a Concatenate check box to see a cumulative record of previous actions; otherwise, only the last action is shown. Selecting Concatenate can degrade performance, particularly when displaying large result sets.To connect using a data source, DataDirect Test needs to access a JNDI data store to persist the data source information. By default, DataDirect Test is configured to use the JNDI File System Service Provider to persist the data source. To download the JNDI File System Service Provider, go to:Make sure that the fscontext.jar and providerutil.jar files from the download are on your classpath.
1 From the main Test for JDBC Tool window menu, select Connection / Connect to DB via Data Source. The Select A Datasource window appears.
2 Select a data source from the Defined Datasources pane. In the User Name and Password fields, type values for the User and Password connection properties; then, click Connect. For information about JDBC connection properties, refer to the appropriate driver chapter in the DataDirect Connect Series for JDBC User’s Guide.
3 If the connection was successful, the Connection window appears and shows the Connection Established message in the JDBC/Database Output scroll box.
1 From the main Test for JDBC Tool window menu, select Driver / Register Driver. DataDirect Test prompts for a JDBC driver name.
2 In the Please Supply a Driver URL field, specify a driver (for example com.ddtek.jdbc.sqlserver.SQLServerDriver); then, click OK.If the driver was registered successfully, the main Test for JDBC Tool window appears with a confirmation in the JDBC/Database Output scroll box.
3 Select Connection / Connect to DB from the main Test for JDBC Tool menu. The Select A Database window prompts with a list of default connection URLs.
4 Select one of the default driver connection URLs. In the Database field, modify the default values of the connection URL appropriately for your environment.NOTE: There are two entries for DB2—one with locationName and another with databaseName. If you are connecting to:
■ DB2 for Linux/UNIX/Windows, select the entry containing databaseName.
■
5 In the User Name and Password fields, type the values for the User and Password connection properties; then, click Connect. For information about JDBC connection properties, Refer to the appropriate driver chapter in the DataDirect Connect Series for JDBC User’s Guide.
6 If the connection was successful, the Connection window appears and shows the Connection Established message in the JDBC/Database Output scroll box.
1 From the Connection window menu, select Connection / Create Statement. The connection window indicates that the creation of the statement was successful.
2 Select Statement / Execute Stmt Query. DataDirect Test displays a dialog box that prompts for a SQL statement.
3
4 Select Results / Show All Results. The data from your result set displays in the JDBC/Database Output scroll box.
5 Scroll through the code in the Java Code scroll box to see which JDBC calls have been implemented by DataDirect Test.
1 From the Connection window menu, select Connection / Create Prepared Statement. DataDirect Test prompts you for a SQL statement.
2
3
d Click Set to pass this information to the JDBC driver.
4 When you are finished, click Close.
5 Select Statement / Execute Stmt Update. The JDBC/Database Output scroll box indicates that one row has been inserted.
6
7 If you repeat the steps described in “Executing a Simple Select Statement”, you will see that the previously inserted records are also returned.
1
2 Select MetaData / Show Meta Data. Information about the JDBC driver and the database to which you are connected is returned.
3 Scroll through the Java code in the Java Code scroll box to find out which JDBC calls have been implemented by DataDirect Test.Metadata also allows you to query the database catalog (enumerate the tables in the database, for example). In this example, we will query all tables owned by the user SCOTT.
4
5
6 Click Ok. The Connection window indicates that getTables() succeeded.
7
1 From the Connection window menu, select Connection / Create JDBC 2.0 Statement. DataDirect Test prompts for a result set type and concurrency.
a In the resultSetType field, select TYPE_SCROLL_SENSITIVE.
b In the resultSetConcurrency field, select CONCUR_READ_ONLY.
c
3
4
5 Select Results / Scroll Results. The Scroll Result Set window indicates that the cursor is positioned before the first row.
6 Click the Absolute, Relative, Before, First, Prev, Next, Last, and After buttons as appropriate to navigate through the result set. After each action, the Scroll Result Set window displays the data at the current position of the cursor.
7 Click Close.Batch execution on a prepared statement allows you to update or insert multiple records simultaneously. In some cases, this can significantly improve system performance because fewer round trips to the database are required.
1
2
d Click Set.
4
5 Select Statement / Execute Stmt Batch. DataDirect Test displays the rowcount for each of the elements in the batch.
6 If you re-execute the Select statement from “Executing a Simple Select Statement”, you see that the previously inserted records are returned.
1
2
1
2 Select TRANSACTION_COMMITTED from the Transaction Isolation drop-down list. Do not select the Auto Commit check box.
3
4 From the Connection window menu, select Connection / Load and Go. The Get Load And Go SQL window appears.
5 Type a statement and click Submit.
6
8 Click Apply; then, click Close. The Connection window indicates whether or not the savepoint succeeded.
10 Select Connection / Rollback Savepoint. In the Rollback Savepoints window, specify the savepoint name.
11 Click Apply; then, click Close. The Connection window indicates whether or not the savepoint rollback succeeded.Click Submit; then, click Close. The Connection window displays data that was inserted before the first Savepoint. The second insert was rolled back.The following examples explain the concept of updatable result sets by deleting, inserting, and updating a row.
1
a In the resultSetType field, select TYPE_SCROLL_SENSITIVE.
b In the resultSetConcurrency field, select CONCUR_UPDATABLE.
3
4
5
6
7 Click Next. Current Row changes to 1.
8 Click Delete Row.
9 To verify the result, return to the Connection menu and select Connection / Load and Go. The Get Load And Go SQL window appears.
10
1
a In the resultSetType field, select TYPE_SCROLL_SENSITIVE.
b In the resultSetConcurrency field, select CONCUR_UPDATABLE.
3
4
5
6
7 Click Move to insert row; Current Row is now Insert row.
9 Select the second row in the top pane. Change the Data Type to String. In Set Cell Value, enter RESEARCH. Click Set Cell.
10
11 Click Insert Row.
12 To verify the result, return to the Connection menu and select Connection / Load and Go. The Get Load And Go SQL window appears.
13
1
a In the resultSetType field, select TYPE_SCROLL_SENSITIVE.
b In the resultSetConcurrency field, select CONCUR_UPDATABLE.
3
4
6
7
8 Click Next. Current Row changes to 1.
9
10 Click Update Row.
11 To verify the result, return to the Connection menu and select Connection / Load and Go. The Get Load And Go SQL window appears.
13 The following example uses Clob data; however, this procedure also applies to Blob data. This example illustrates only one of multiple ways in which LOB data can be processed.
1
2
4
5
6 Click Next. Current Row changes to 1.
7 Deselect Auto Traverse. This disables automatic traversal to the next row.
8 Click Get Cell. Values are returned in the Get Cell Value field.
10 Click Get Cell. The Clob data window appears.
11 Click Get Cell. Values are returned in the Cell Value field.