e股脑电脑教程网
  • 首 页
  • 操作系统
  • 应用软件
  • 下载工具
  • 影音视频
  • 办公软件
  • 媒体制作
  • 网站建设
  • 平面设计
  • 数据库
  • 程序开发
  • 视频教程
编辑推荐: | 文章搜索:
您现在的位置: e股脑 >> 数据库 >> DB2教程 >> DB2 UDB 连通性快捷表 第 4 部分 >> 教程正文
 
教程搜索
 
 
相关教程
  • 数据挖掘器: 警告 — 及时采取行动
  • UNIX、Linux 和 Windows 的生动简介
  • “总览图”: IBM DB2 通用数据库和信息
  • DB2 大事记
  • 数据管理部门副总裁兼 CTO:Don Hader
  • IBM 联邦数据库技术
  • 唐纳德.海德勒(Donald J. Haderle)
  • 数据库未来展望
  • 哪一个分布式 DB2 UDB V8 版本适合您?
  • 从数据管理到信息集成: 自然的演变
  • 联邦 - 数据库互操作性(第 1 部分)
  • 成功是必然的(中)
  • 成功是必然的(上)
  • 成功是必然的(下)
  • DB2 信息集成: 总览图
  • IBM 杰出工程师兼信息集成主管 Nelson
 
 

图文教程


  • Windows抢了谁的饭碗 非主流操作系统To

  • 地球还是火星 平常心看“非主流”

  • 综合运用Office 2007批量制作奖状

  • 没有系统盘如何才能修复受损系统?

  • 巧妙运用Excel中边界的附加功能!
 
 
赞 助 商
 
 
DB2 UDB 连通性快捷表 第 4 部分
  • 来源:e股脑
  • 点击次数:
  • 更新时间:2007-8-9
************ import java.sql.*; class DBConn_Type2U { public static void main(String argv[]) { // Check arguments if (argv.length < 3){ System.out.println("Usage: java DBConn_Type2U <database name> <userid> <password>"); return; } try { String dbname = argv[0]; String userId = argv[1]; String password = argv[2]; String url = " jdbc:db2:" + dbname; String v_IBMREQD = null; // Registering driver and connecting Class.forName(" com.ibm.db2.jcc.DB2Driver").newInstance(); Connection con = DriverManager.getConnection( url, userId, password ); System.out.println( " Successful connection to '" + dbname + "' db with JDBC type 2 Universal driver"); - // !!! Note: The code after the above line is exactly // the same as in listing 3 , so we have removed it // from this listing due to space limitations in the article !!! } // DBConn_Type2U

表 7. 使用 IBM DB2 UDB JDBC Type 2 驱动程序(通用驱动程序)从 DB2 UDB for Linux、UNIX 和 Windows 连接到 DB2 UDB 服务器(任何平台)


Machine 1(‘myblue’)DB2 UDB for Linux、UNIX 和 Windows Machine 2(‘aries’)DB2 UDB 服务器(任何平台) 在这台机器上运行下列命令: 您需要从这台机器上获取下列信息,以便在 machine 1 上执行命令: 第一部分:配置连通性 db2 catalog tcpip node mynode remote 9.23.190.24 server 50000

db2 catalog db sample at node mynode

db2 terminate

请参阅该系列文章的 第 1 部分以获得连通性设置的详细指导 第二部分:编译使用 DB2 Type 2 通用驱动程序的 JDBC 程序 javac DBConn_Type2.java

在 JDBC 程序中要注意的事项:

  • URL 的格式必须为:jdbc:db2:<dbname>
  • 通过 com.ibm.db2.jcc.DB2Driver 指定 type 2 通用驱动程序。

* 注意事项:

  • DB2 运行时客户机是运行 JDBC 程序的最低要求;然而,如果需要对您开发的程序进行编译,就必须使用 DB2 UDB 应用程序开发客户机(DB2 UDB Application Development client)。
  • DB2 type 2 通用驱动程序存储在 sqllib\\java 下的文件 db2jcc.jar 之中。
  • 应确保已正确设置了环境变量(请参阅 表 1中的实例)
第三部分:执行程序 java DBConn_Type2U sample db2admin mypsw
  • 该示例程序被设计为按此次序获取 3 个参数:<数据库名> <用户 ID> <密码>
  • ‘Sample’是此客户端机器上的 catalog db 命令中为数据库名指定的别名。默认情况下,如果没有在该命令中指定别名,那么数据库名就相当于别名
sample = 数据库名

db2admin = 服务器上的用户 ID


mypsw = 服务器上的密码

图 13. DBConn_Type2U.java 程序输出

如图 13 所示,type 2 通用驱动程序不能正确地对 iSeries 数据库工作。该故障故障已经报告给了 DB2 UDB 故障检查支持(其故障记录号(problem record number,PMR)为 43211,057,649)。

场景 7 - 使用 IBM DB2 UDB type 3 驱动程序(网络驱动程序)连接 DB2 UDB 数据库

JDBC Type 3 驱动程序遭到了贬低(它依然被支持,但今后不会得到增强)。从 DB2 UDB for Linux、UNIX 和 Windows V8 开始推荐用 type 4 驱动程序来代替它,这将提供更好的性能。为了完整起见,我们在本文中包括了该场景,但仅仅用于 DB2 UDB for Linux, UNIX and Windows。

图 14. 使用 IBM DB2 UDB type 3 驱动程序从 JDBC 应用程序客户机连接到 DB2 UDB for Linux、UNIX 和 Windows 服务器

清单 6 中提供了 JDBC 示例程序 DBConn_Type3.java。

清单 6. DBConn_Type3.java

//***************************************************************** //SOURCE FILE NAME: DBConn_Type3.java //***************************************************************** import java.sql.*; class DBConn_Type3 { public static void main(String argv[]) { // Check arguments if (argv.length < 5) { System.out.println("Usage: java DBConn_Type3 <database name> <userid> <password>"); System.out.println(" <server hostname> <DB2's Java Applet Server port>"); return; } try { String dbname = argv[0]; String userId = argv[1]; String password = argv[2]; String server = argv[3]; String portNumber = argv[4]; String url = " jdbc:db2://" + server + ":" + portNumber + "/" + dbname; String v_IBMREQD = null; // Registering driver and connecting Class.forName(" COM.ibm.db2.jdbc.net.DB2Driver").newInstance(); Connection con = DriverManager.getConnection( url, userId, password ); System.out.println( "Successful connection to '" + dbname + "' db using JDBC type 3 driver"); - // !!! Note: The code after the above line is exactly the same // as in listing 3 , so we have removed it from this listing // due to space limitations in the article !!! } // DBConn_Type3


表 8. 使用 IBM DB2 UDB JDBC Type 3 驱动程序从 DB2 UDB for Linux、UNIX 和 Windows 连接到 DB2 UDB 服务器(任何平台)

Machine 1(‘myblue’)DB2 UDB for Linux、UNIX 和 Windows Machine 2(‘aries’)DB

上一页  1 2 3 4 5 6 7 8 9 10 下一页
  • 上一篇教程: 如何在DB2上为AIX5L设置unixODBC
  • 下一篇教程: 监控和估计
  •  

    关于本站 | 广告联系 | 版权声明 | 使用帮助

    Copyright © 2004-2008 www.egunao.com All rights reserved.