![]() ![]() The DB2 server in this case is listening for client connections on URL takes the form jdbc:db2://server1:50000/phonedb (as opposed to the form Listing 3 Use of the Universal driver (db2jcc.jar) in a JDBC Type 4 Syntax of Listing 2 (showing the use of the Universal driver as JDBC Type 2ĭriver) and Listing 3 (showing the use of the Universal driver as a JDBC Type 4ĭriver). Implementation package name is again: .DB2Driver.)Īt a quick glance, it is a bit difficult to see the difference between the Weĭemonstrate how to connect to our DB2 server in Listing 3. The Universal driver regardless of communication mode (Type 2 or Type 4). Remote databases as with the Type 2 driver. In a Type 4 setup, no client Configuration Assistant is needed to catalog (Refer to Figure 1 for an illustration of this interaction.) import Ĭlass.forName(".DB2Driver") Ī Type 4 JDBC driver connects directly to the database server using Java. ![]() Listing 2 Use of the Universal driver (db2jcc.jar)in a JDBC Type 2 setup to Thisįile is installed when the Runtime Client or Application Development client of Type 2 mode and attempt will be made to load a file named db2jcct2.dll. The implementation package is .DB2Driver. Theĭriver is located in the file db2jcc.jar. Machine, we recommend that you use the Universal JDBC driver in Type 2 mode. Therefore, if the application and the DB2 server are on the same In Type 2 mode, there is also full support for distributed Gains (because it avoids using TCP/IP protocol to communicate to the DB2 Type 2 mode, the Universal JDBC driver provides local application performance Used either in a Type 2 architecture or a Type 4 architecture (see below). With the advent of DB2 8.1 came the new Universal JDBC driver, which can be Figure 4 shows the successfulĤ Successful execution of our sample code. Only difference is that they use the different drivers, driver architectures,Īnd syntax to achieve their connectivity. Good idea to take a look at articles on this topic on the InformIT site.) The We are assuming that you have a background in JDBC. String phoneNumber = resultSet.getString("phonenumber") String name = resultSet.getString("name") cycle through the resulSet and display what was grabbed ResultSet resultSet = st.executeQuery(myQuery) String myQuery = "SELECT * FROM PHONENUMBERS" Statement st = db2Conn.createStatement() use a statement to gather data from the database Listing 1 Use of the legacy/CLI JDBC driver (db2java.zip), a JDBC-typeĭriver to interact with DB2 import Ĭlass.forName(".app.DB2Driver") Simply retrieve data from the database we created using a simple SQL query. Listing 1, 2, and 3 all do the same thing. Note that the implementation package name isĬom.DB2Driver. ![]() The code of Listing 1 shows the programmatic access of the database weĬreated earlier. This can be done using theĬonfiguration Assistant, as shown in Figure 3. Idea to ensure connectivity to your remote database. The JDBC driver to locate the DB2 database on a remote server.īefore you start your endeavors of hooking up to DB2 via Java, it is a good If you are just getting started with DB2 locally on your own machine we wouldįigure 2 shows the DB2 Configuration Assistant (db2ca), it can be used toĬatalog the DB2 database and the node directory information that will be used by License jar file from an existing installation. Really need, you can simply copy the db2jcc.jar file and its corresponding If you decide that the Universal JDBC driver in type 4 mode is all you These clients are downloadable for free atįor Java development, the only required DB2 software is the runtime client,Īnd it is a much smaller download image (around 68MB for Windows and 200MB for Should install the DB2 Application Development Client or the DB2 Runtime Client. If you are connecting to a remote DB2 server, you Installed a DB2 UDB v8 server, you will have the Configuration Assistant and the This driver performs a native connect through a local DB2 client. ![]() JDBC driver, you need to use the DB2 Configuration Assistant. If you are trying to interact with a remote database using the legacy/CLI The default DB2 installation directory, "c:\Program The legacy/CLI JDBC driver is provided in the file db2java.zip which is in This interaction is illustrated in Figureġ JDBC Type 2 driver implementation: the legacy/CLI JDBC driver. DB2 ships with two different type 2 drivers: the legacy/CLI JDBCĭriver and the universal JDBC driver. JDBC 2 Type 2 drivers use an OS-specific library to facilitate communication DB2 currently offers JDBC drivers known as legacy/CLI drivers and The implementation is known asĪ JDBC driver. Interfaces that implement the JDBC specification. DB2 UDB provides for JDBC connectivity through a number of Java classes and ![]()
0 Comments
Leave a Reply. |