26
IBM Informix 11.50 Java Application Development Information Management Partner Technologies 1

2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

IBM Informix 11.50 Java Application Development

Information Management Partner Technologies

1

Page 2: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

Contents

Table of Contents1. Introduction ............................................................................................................. 3 2. Suggested reading ................................................................................................... 4 3. Creating the Sample Database ................................................................................ 5 4. Using the IBM Data Server Driver for JDBC and SQLJ ........................................ 7

4.1 Setting up the Driver ................................................................................................. 7 4.2 Using the Provided VMware image .......................................................................... 7 4.3 General Setup ............................................................................................................ 9

5. Writing a JDBC (JCC) application using Data Studio .......................................... 11 5.1 Calling a Stored Procedure ...................................................................................... 19

6. Troubleshooting .................................................................................................... 21

2

Page 3: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

1. Introduction

In this lab, you will learn how to set up and use the IBM Data Server Driver forJDBC and SQLJ (also known as the JCC driver).You will also learn how to use the pureQuery technology in conjunction with DataStudio to simplify application programming.

For a Java application to access Informix Dynamic Server, it requires a driverthat handles the actual access. A common specification for such a driver is theJava DataBase Connectivity specification – or JDBC. For Informix, there are twodrivers that implement this specification:

1. Informix JDBC Driver2. IBM Data Server Driver for JDBC and SQLJ (also known as Java Common

Client driver – JCC)

The Informix JDBC Driver is older and the recommended driver is the IBM DataServer Driver for JDBC and SQLJ.

The Informix JDBC Driver uses the Informix proprietary SQLI protocol whereasthe IBM Data Server Driver uses the Distributed Relational DatabaseArchitecture (DRDA) protocol. The protocol is also used by DB2 for example andthe specification is openly available.

However, there are still some issues that might force you to use the InformixJDBC Driver. The following table serves as an overview of features that mightimpact your decision as to which driver to use (as of IBM Data Server DriverVersion 3.53):1

Informix JDBC Driver IBM Data Server DriverDRDA Connections xSQLI Connections xInformix version < 11.10 xJDBC 4.0 Functionality x

1 Not a complete list of differences, for more information see: http://publib.boulder.ibm.com/infocenter/idshelp/v115/topic/com.ibm.jccids.doc/com.ibm.db2.luw.apdv.java.doc/doc/r0052865.htm

3

Page 4: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

Informix JDBC Driver IBM Data Server Driver

INTERVAL,opaque- anduser-defined data types,collection data types

x

Automatic client re-route(failover)

x

In this lab we will only use the IBM Data Server Driver for JDBC and SQLJ.

2. Suggested reading

IBM Informix 11.50 Information Center publib.boulder.ibm.com/infocenter/idshelp/v115/index.jsp

IBM Data Server Driver for JDBC and SQLJ for Informix guide:publib.boulder.ibm.com/infocenter/idshelp/v115/topic/com.ibm.jccids.doc/jcc.htm

developerWorks series on pureQuery technology:www.ibm.com/developerworks/views/db2/libraryview.jsp?search_by=understanding%20purequery

4

Page 5: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

3. Creating the Sample Database

In this Lab, you will write a simple time tracking application that periodically pollsthe user for information about what they are doing. For this purpose, there is adatabase table containing activities that a user can choose from, and a table thattracks what the user was doing during the last interval.

This information will be stored in a simple database, that you will create byfollowing these steps:

Open a terminal window in your VMware session and set up your environmentfor the “demo_on” Informix instance:

$ . setDemo (note the space after the “.” )

Next, start DB-Access to create the database:$ dbaccess - -(note the space between hyphens)

Important: If you do not want to create the database manually, you can run thefollowing script and ignore the rest of this section:$ dbaccess - /home/informix/scripts/sqls/javalab_create_act_tracks.sql

5

Page 6: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

Enter the following DDL statements in DB-Access to create the database:create database javalab;

database javalab;

CREATE TABLE activities( aid SERIAL NOT NULL, name CHAR(20) NOT NULL, description VARCHAR(100), PRIMARY KEY(aid) CONSTRAINT activities_PK);

CREATE TABLE tracks( aid INTEGER NOT NULL, start DATETIME YEAR TO SECOND NOT NULL, end DATETIME YEAR TO SECOND NOT NULL, PRIMARY KEY(aid, start, end) CONSTRAINT tracks_PK, FOREIGN KEY(aid) REFERENCES activities(aid) ON DELETE CASCADE);

Note that deleting an activity also deletes the corresponding tracking information,but not the other way around.

Insert a couple of activities into the ACTIVITIES table by issuing the followingINSERT statements in the DB-Access window:

INSERT INTO activities(name, description) VALUES('Email', 'Checking andanswering emails');

INSERT INTO activities(name, description) VALUES('Calls', 'Conferenceand regular phone calls');

INSERT INTO activities(name, description) VALUES('Education', 'Reading,getting up to date, Training classes etc.');

INSERT INTO activities(name, description) VALUES('Random', 'Time spentfor random things, that do not fit into the other activities');

This will serve as the example database for this lab. Of course you can addfurther activities if you would like.

6

Page 7: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

4. Using the IBM Data Server Driver for JDBC andSQLJ

4.1 Setting up the DriverThe Java Common Client (JCC) is the IBM Data Server Driver for JDBC andSQLJ. The driver itself requires no installation, you just have to make sure thatthe driver file is accessible from your application.First we describe the steps necessary to get a JAVA project up in running in IBMData Studio with the JCC driver, and then we describe the general set upprocedure that you can follow on any other machine.

4.2 Using the Provided VMware imageStart IBM Data Studio by double-clicking the Data Studio icon on the Desktop inyour VMware session. You can accept the default workspace when prompted.And click “Ignore” if you get a message that the trial license will expire soon.Also close the welcome screen.

You should now see Data Studio using the Data perspective. If it does not looklike the following screenshot, try Window->Open Perspective->Other andselect the “Data” perspective):

7

Page 8: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

• From the main menu at the top of the window select“Window ->Preferences...” and navigate to “Java”->”Build Path”->”UserLibraries”

You will now add a new user library for the JCC driver. This way, you can easilyinclude it in future projects and have a central place to change the driver, forexample, when a new version becomes available.

• Click “New...” , as the name type “JCC” and click OK• Click “Add JARs...”• Navigate to and add “/opt/IBM/SDPShared/plugins/

com.ibm.datatools.db2_2.1.0.v20090605_2309/driver/db2jcc.jar” (NOTE:the path might be slightly different, depending on the driver version)

You should see the following window:

8

Page 9: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

• Click OK.

You have just created a user library for easy inclusion in future projects.

4.3 General SetupImportant: You do NOT have to perform these steps in the classroomenvironment. You will do this when configuring your own developmentenvironment.

Download the “IBM Data Server Driver for JDBC and SQLJ” fromhttps://www14.software.ibm.com/webapp/iwm/web/reg/download.do?lang=en_US&source=swg-informixfpd&S_PKG=dl&cp=UTF-8

The download contains the files db2jcc.jar, db2jcc4.jar and sqlj.zip. If you wantto develop an application that uses JDBC 4.0 functionality, you need the filedb2jcc4.jar, otherwise db2jcc.jar is sufficient (to use SQLJ you need sqlj.zip).

If you are developing with Data Studio, all you need to do is include the properdriver files from the download above and put them in your project build path.Right-click on your JAVA project and select “Build Path”->”Add ExternalArchives...” from the context menu to add the file (or read the previous sectionabout how to add the driver as a user library.)

9

Page 10: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

To have the driver always available (or if you are not using Data Studio) youmight also want include the driver file(s) in your JAVA CLASSPATH.To do so, copy the appropriate files to a location of your choice and include thisdirectory in the CLASSPATH environment variable.For example, under Windows, if you needed JDBC 4.0 functionality, you couldcopy db2jcc4.jar to C:\java\libs and append C:\java\libs to the CLASSPATHenvironment variable.

10

Page 11: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

5. Writing a JDBC (JCC) application using DataStudio

Launch IBM Data Studio by double clicking on the Data Studio icon on theDesktop in your VMware session. You can accept the default workspace whenprompted.

You should now see Data Studio using the Data perspective. If it does not looklike the following screenshot, try Window->Open Perspective->Other and selectthe “Data” perspective):

• Right click somewhere in the “Data Project Explorer” area and select“New”->”Project...”. You can also do this by going to“File”->”New”->”Project...”.

• Expand the “Java” folder, select “Java Project” and click “Next”. You shouldnow see the following window:

11

Page 12: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

• As the project name, enter “TimeTrackerJCC” and change the project layoutto “Create separate source and output folders” to get a tidier project.

• Click “Next” and select the “Libraries” tab:

• Click “Add Library...”• Select “User Library”• Select the “JCC” library that you created in the previous section.• Click “Finish” to complete the creation of your JAVA project.

12

Page 13: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

Data Studio may prompt you to change into the JAVA perspective. You caninstruct it to do so at this time.You can get back to the “Data” perspective by selecting it from the top rightcorner or “Window->Open Perspective...”.

You will now create a new Java Class:• Right-click on the source folder of your new project and select “New->Class”

from the context menu

• As the package, enter “com.ibm.bootcamp.ids”.• For the name, enter “TimeTracker”.• Check the option to create “public static void main”.• Click “Finish” to create the Class.

13

Page 14: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

You will now fill in the “main” method with the necessary steps to create a JDBCconnection to an Informix instance (using the DRDA protocol). In this documentwe will describe the data access related steps. The source code can be found inthe file: /home/informix/scripts/java/TimeTracker.java

There are two ways to access the data:• using the DriverManager interface from the java.sql package• using the DataSource interface

If you need more flexibility regarding the underlying data source, you should usethe DataSource interface. That way you can, for example, have a WebSphereapplication server manage the data source resources.

In this example, we will use the DriverManager interface. You can obtain moreinformation about the DataSource interface in the Informix v11.50 InformationCenter2.

The first step is to load the driver class via the Class.forName method. In JDBC4.0 (db2jcc4.jar) this is no longer required, but in this lab you are usingdb2jcc.jar.

2 http://publib.boulder.ibm.com/infocenter/idshelp/v115/topic/com.ibm.jccids.doc/com.ibm.db2.luw.apdv.java.doc/doc/tjvdscon.htm

14

Page 15: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

String driverClass = "com.ibm.db2.jcc.DB2Driver";try{

Class.forName( driverClass );} catch( ClassNotFoundException e){

System.out.println("error loading class " + driverClass );e.printStackTrace();

}

Next, create a connection string. To obtain a connection object, you need tobuild up the connection string first. For Informix, it starts with “jdbc:ids:”, thenthe Informix server address and the database name. For example:

String url = "jdbc:ids://ids1150srvr:9089/javalab:retrieveMessagesFromServerOnGetMessage=true;DELIMIDENT=true;";

You can also add additional configuration properties to the end of the string. Thefollowing table summarizes some of the commonly used ones.

15

Page 16: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

Property DescriptionretrieveMessagesFromServerOnGetMessage=true

When you call getMessage for anSQLException object you also get amore meaningful message from theserver, for example also “A syntaxerror has occurred..” and not only “SQLCODE=-201, SQLSTATE=42000,DRIVER=3.52.90”

DELIMIDENT=true Causes Informix to interpret strings indouble quotes as SQL identifiers andstrings in single quotes as stringliterals

blockingReadConnectionTimeout=x Number of seconds before a socketread times out (default is 0, whichmeans no timeout)

deferPrepares True or false, default is to deferprepares until the statement isexecuted. Depending on yourapplication scenario it might be betterperforming to execute preparesimmediately (deferPrepares=false)

STMT_CACHE 0 turned off1 enables a 512KB statement-cache

traceXXX See troubleshooting sectionFor more properties see http://publib.boulder.ibm.com/infocenter/idshelp/v115/index.jsp?topic=/com.ibm.jccids.doc/com.ibm.db2.luw.apdv.java.doc/doc/rjvdsprp.htm

Now, obtain a connection object via the DriverManger interface:

Connection con = DriverManager.getConnection(url, "informix", "informix");

If the connection fails, the method throws an SQLException, otherwise you willbe connected to the Informix instance.

To issue an SQL statement, you first need a Statement object:

Statement stmt = con.createStatement();

16

Page 17: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

By default, each statement is automatically wrapped into an transaction.If you want to commit your changes manually you have to toggle theAUTOCOMMIT property on the connection object using thecon.setAutoCommit(false); statement and then issuing the con.commit(); statement tocommit your changes. You can use the default behavior for this exercise.

Create a timer object, which will be used to mark the beginning of the currentactivity:

Timestamp start = new Timestamp(System.currentTimeMillis());

Now, you will issue a query to retrieve all activities from the ACTIVITIES tableand handle the ResultSet returned, in order to present the user with a list ofactivities to choose from:

String queryActivities = "SELECT aid, name, description FROM activities";ResultSet rs = stmt.executeQuery( queryActivities);

int aid;String name;String description;

System.out.println("What are you doing right now?");System.out.println();

while( rs.next() ){aid = rs.getInt("aid");name = rs.getString("name");description = rs.getString("description");System.out.println( aid + ") " + name + " " + description);

}

rs.close();

stmt.close();

Now it is time to get the selection from the user. The user will need to enter aninteger value. To quit the program, the user can simply type an integer valuethat does not exist as a key value for an activity, as this will generate anSQLException.

The following loop is a nice and simple way to make sure that the user actuallyentered a valid integer value:

17

Page 18: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

String input = "";int sel;BufferedReader br = new BufferedReader(

new InputStreamReader(System.in) );

while(true){

System.out.println("Please type the number for an activity from above (none existing to exit): ");

try{input = br.readLine();

}catch(IOException e){

System.out.println("error reading from standard input");}

try{sel = Integer.parseInt(input);

}catch(NumberFormatException e){

System.out.println("input was no number");continue;

}

// we got a number, exit loopbreak;

}

Now that you know which activity the user is doing, you can insert it into thedatabase. This time, you will use a Prepared Statement:

Timestamp end = new Timestamp(System.currentTimeMillis());

PreparedStatement pstmt = con.prepareStatement( "INSERT INTO tracks(aid, start, end) VALUES(?, ?, ?)");

pstmt.setInt(1, sel);pstmt.setTimestamp(2, start);pstmt.setTimestamp(3, end);

pstmt.execute();

pstmt.close();

start.setTime( System.currentTimeMillis() );

At the end of the program, don't forget to close the connection:con.close();

This small time tracking program is now ready. The source file in /home/informix/scripts/java/TimeTracker.java in your VMWare image also contains aloop to periodically poll the user for activity information.

Right-click on the file “TimeTracker.java” in the Package Explorer and select“Run as->Java Application”. As you already know, you will be prompted toenter what you are doing right now :-) .

18

Page 19: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

5.1 Calling a Stored ProcedureFirst, create a stored procedure called “activity_time_for_day” that computeshow much time was spent for an activity for a specified day. If you are familiarwith the Informix Stored Procedure Language (SPL) please feel free to try writingit yourself3).

We have also included a script to automatically create this procedure for you.Execute the following command in your terminal window:

$ dbaccess javalab /home/informix/scripts/sqls/javalab_spl.sql

Now that the stored procedure is created, you can extend the simple Javaprogram to call the stored procedure after the user selects the activity in order toprint how much time was already spent on that activity today.

You can enter the following code after the user selection is contained in the “sel”variable and before the connection is closed.

To call a stored procedure, you need a CallableStatement object:

CallableStatement cstmt = con.prepareCall( "CALL activity_time_for_day(?, ?, ?)" );

cstmt.setInt(1, sel);Date today = new Date( System.currentTimeMillis() );cstmt.setDate(2, today);cstmt.registerOutParameter(3, Types.VARCHAR);

This code creates the object, and sets the parameters for the stored procedure.The first one is an integer that specifies the activity code and the second one is aDATETIME YEAR TO SECOND which maps to a java.sql.date (NOTjava.util.date) object.4 The third parameter is an OUT parameter with a data typeof java.sql.Types.VARCHAR.

3 You have to use an OUT parameter and not a return value, otherwise Data Studio (as ofversion 1.2) will sort it under User-Defined Functions and not allow the generation ofpureQuery code

4 We want to use the local time from the client here, this is why we do not simply use the“CURRENT” keyword.

19

Page 20: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

Call the stored procedure and retrieve the OUT parameter:

cstmt.execute();

String interval = cstmt.getString(3);System.out.println("Time already spent for this activity

today (hh:mm:ss): " + interval);

cstmt.close();

At the end close the CallableStatement, and you are done!

Right-click on the file in the Package Explorer and select “Run as->JavaApplication” to test out the modifications.

Result SetsIf the stored procedure returned a result (or a result set), you could handle thatusing the following code:

ResultSet r = cstmt.executeQuery();while( r.next() ){

String name = r.getString(1);System.out.println("Name): " + name);

}r.close();cstmt.close();

20

Page 21: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

6. Troubleshooting

This section provides an introduction to troubleshooting. It contains somecommonly encountered issues and shows how to take a JDBC trace, amongother things.

FinderrThe Informix Client SDK contains a very useful utility called “finderr”. If youinstalled the CSDK it is in the $INFORMIXDIR/bin directory.You can use it to get meaningful explanations for error codes. This is also helpfulfor the errors returned by SQLException.getMessage. If for example you seeSQLCODE=-201 in the output of getMessage you can then open a terminal windowand navigate to $INFORMIXDIR/bin (not necessary if it is in your path) and type:

$ finderr 201

The finderr utility then prints very detailed information about what might havecaused that error and that, in this case, it was most likely a syntax error.

If you do not get an SQLCODE, but an ERRORCODE for example, you can usethe connection URL property retrieveMessagesFromServerOnGetMessage=true to get ameaningful error message when catching SQLException and calling getMessagefor that exception (as described earlier).

pureQuery and SERIAL ColumnsIf you generate pureQuery code for a column with a SERIAL data type, you willget an error like the following for the method generated for @Update

21

Page 22: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

Since SERIAL columns can not be updated in Informix, you have to remove the“AID=?” from the SQL statement for the two @Update statements. In ourexample, remove the “Integer aid” from the first method signature so that it lookslike the following:

Afterwards the project has to be rebuilt.

Connection to Informix failed.

When using the IBM Data Server Driver for JDBC and SQLJ, you have toconnect to an Informix instance running at least version 11.10 which has aDRDA entry in the SQLHOSTS file.

If you are trying to connect to a port that uses the SQLI protocol, you will get thefollowing error message (in Data Studio when testing the connection):

22

Page 23: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

(Connection to Informix failed. [jcc][t4][2030][11211][3.52.90] A communication error occuredduring operations on the connection's underlying socket, socket input stream or socket outputstream. Error location: Reply.fill(). Message: Insufficient data. ERRORCODE=-4499,SQLSTATE=08001)

Solution:

Make sure that you have an entry in your SQLHOSTS file with the connectiontype drsoctcp as well as a corresponding DBSERVERALIASES value.

For example, in the following SQLHOSTS file, the second entry is configured forDRDA:

fox1 onsoctcp suse1 9088fox1drda drsoctcp suse1 9089

and in the ONCONFIG file:

DBSERVERNAME fox1DBSERVERALIASES fox1drda

Connection to Informix (still) failed.If you still cannot connect to your Informix Instance but you are sure that theserver is reachable (e.g. via ping), you might want to check that the hosts file onthe machine that runs Informix is correct. Especially if it is inside a VMwareimage, make sure that you have an entry with the correct IP Address (127.0.0.1is NOT sufficient) and the hostname used in the SQLHOSTS file. For exampleon a Linux host in /etc/hosts:

192.168.42.133 suse1.localdomain suse1

would be a valid entry if you can reach your VMware host system with thisinterface.

23

Page 24: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

JDBC traceTo troubleshoot an application, it is often very useful to get a trace of the JDBCcalls and actions that the application performed. There are several ways to starta JDBC trace5. We will use the simplest method here by providing several traceparameters via the connection URL:

String url = "jdbc:ids://suse1:9089/javalab:retrieveMessagesFromServerOnGetMessage=true;DELIMIDENT=true;"

+ "traceDirectory=/home/informix/trace;traceFile=traces_;traceFileAppend=true;traceLevel=" + com.ibm.db2.jcc.DB2BaseDataSource.TRACE_STATEMENT_CALLS + ";";

The relevant trace parameters are “traceDirectory” which specifies a directory towhich all the trace files are written. “traceFile” gives a prefix with which eachtrace file starts. If a trace file already exists, the trace output is appendedbecause of “traceFileAppend=true”. The last parameter sets the “traceLevel” totrace statement calls. If you run your sample application with this modifiedconnection URL you will produce a trace file that contains something like:

[jcc][Time:2008-12-28-22:24:52.734][Thread:main][Statement@23cc23cc] executeQuery (SELECT aid, name, description FROMactivities) called[jcc][Time:2008-12-28-22:24:52.812][Thread:main][Statement@23cc23cc] executeQuery () returned ResultSet@4b804b8[jcc][Time:2008-12-28-22:24:52.828][Thread:main][Statement@23cc23cc] close () called[jcc][Time:2008-12-28-22:24:55.984][Thread:main][PreparedStatement@7cf87cf8] setInt (1, 2) called[jcc][Time:2008-12-28-22:24:55.984][Thread:main][PreparedStatement@7cf87cf8] setTimestamp (2, 2008-12-28 22:24:33.562)called[jcc][Time:2008-12-28-22:24:55.984][Thread:main][PreparedStatement@7cf87cf8] setTimestamp (3, 2008-12-28 22:24:55.937)called[jcc][Time:2008-12-28-22:24:55.984][Thread:main][PreparedStatement@7cf87cf8] execute () called[jcc][Time:2008-12-28-22:24:56.000][Thread:main][PreparedStatement@7cf87cf8] execute () returned false[jcc][Time:2008-12-28-22:24:56.000][Thread:main][CallableStatement@245e245e] setInt (1, 2) called[jcc][Time:2008-12-28-22:24:56.000][Thread:main][CallableStatement@245e245e] setDate (2, 2008-12-28) called[jcc][Time:2008-12-28-22:24:56.000][Thread:main][CallableStatement@245e245e] executeQuery () called[jcc][Time:2008-12-28-22:24:56.015][Thread:main][CallableStatement@245e245e] executeQuery () returned ResultSet@57c257c2[jcc][Time:2008-12-28-22:24:56.015][Thread:main][CallableStatement@245e245e] close () called[jcc][Connection@48e848e8] IDS ID: 192.168.42.133.33059.081212134954.0001

Transactions and loggingIf at some point you get an error saying that transactions are not supported (forexample if you are using the setAutoCommit(false) ) you have to turn on loggingfor the database you are working with. In our example, you could do this byopening a terminal window, setting your environment using

$ . setDemo (note the space after the “.”)

5 For other possibilities to turn on JDBC tracing seehttp://publib.boulder.ibm.com/infocenter/idshelp/v115/index.jsp?topic=/com.ibm.jccids.doc/jcc.htm

24

Page 25: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

and then using ontape

$ ontape -s -B javalabThis turns on buffered logging for the database javalab.

This concludes the lab, if you finished ahead of time, you can help yourclassmates or write a simple report application that creates a ranking of theactivities regarding how much time you spent for each one.

25

Page 26: 2.4b Informix Application Development Java Lab · In this lab, you will learn how to set up and use the IBM Data Server Driver for JDBC and SQLJ (also known as the JCC driver). You

© Copyright IBM Corporation 2010All Rights Reserved.

IBM Canada8200 Warden AvenueMarkham, ONL6G 1C7Canada

Printed in United States of America01/2010

IBM, IBM (logo), and Informix are trademarks or registeredtrademarks of International Business Machines Corporation in theUnited States, other countries, or both.

Linux is a trademark of Linus Torvalds in the United States, othercountries, or both

UNIX is a registered trademark of The Open Group in the UnitedStates, other countries, or both

Windows is a trademark of Microsoft Corporation in the UnitedStates, other countries, or both.

Other company, product, or service names may be trademarks orservice marks of others.

References in this publication to IBM products or services do notimply that IBM intends to make them available in all countries inwhich IBM operates. The following paragraph does not apply to theUnited Kingdom or any other country where such provisions areinconsistent with local law:

INTERNATIONAL BUSINESS MACHINES CORPORATIONPROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTYOF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUTNOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR APARTICULAR PURPOSE.

Some states do not allow disclaimer of express or implied warrantiesin certain transactions, therefore, this statement may not apply toyou.

This information could include technical inaccuracies ortypographical errors. Changes are periodically made to theinformation herein; these changes will be incorporated in neweditions of the publication. IBM may make improvements and/orchanges in the product(s) and/or the program(s) described in thispublication at any time without notice.

Any performance data contained herein was determined in acontrolled environment. Therefore, the results obtained in otheroperating environments may vary significantly. Somemeasurements may have been made on development-levelsystems and there is no guarantee that these measurements willbe the same on generally available systems. Furthermore, somemeasurement may have been estimated through extrapolation.Actual results may vary. Users of this document should verifythe applicable data for their specific environment.Information concerning non-IBM products was obtained from thesuppliers of those products, their published announcements orother publicly available sources. IBM has not tested thoseproducts and cannot confirm the accuracy of performance,compatibility or any other claims related to non-IBM products.Questions on the capabilities of non-IBM products should beaddressed to the suppliers of those products.

The information in this publication is provided AS IS withoutwarranty. Such information was obtained from publicly availablesources, is current as of January 2010, and is subject to change.Any performance data included in the paper was obtained in thespecific operating environment and is provided as an illustration.Performance in other operating environments may vary. Morespecific information about the capabilities of products describedshould be obtained from the suppliers of those products.

Information concerning non-IBM products was obtained from thesuppliers of those products, their published announcements orother publicly available sources. IBM has not tested thoseproducts and cannot confirm the accuracy of performance,compatibility or any other claims related to non-IBM products.Questions on the capabilities of non-IBM products should beaddressed to the suppliers of those products.

The information in this publication is provided AS IS withoutwarranty. Such information was obtained from publicly availablesources, is current as of January 2009, and is subject to change.Any performance data included in the paper was obtained in thespecific operating environment and is provided as an illustration.Performance in other operating environments may vary. Morespecific information about the capabilities of products describedshould be obtained from the suppliers of those products.

26