新儒AS/400家园
  •  
       系统规划 | 系统配置 | 规划方案 | 其它 | 投 稿
         相关文章
    Home  首 页 »  其它 »  学习教程 » 

    用JDBC访问AS/400数据(三)- 样例


    作者:fh2001 (fh2001@sina.com)   来源:原创    更新日期:2005-01-12    浏览次数:
     

    附录A : 使用JDBC 驱动器连接AS/400 数据库

     

    你可以使用DriverManager.getConnection() 方法来连接AS/400数据库. DriverManager.getConnection() 使用一个URL字符串作为参数. JDBC驱动器管理器将为尝试连接在URL字符串中所指的数据库:

          "jdbc:as400://systemName/defaultSchema;listOfProperties"

    以下是一些连接方式的例子

    例一:URL不给出系统名。这种情况需要用户在使用时给出欲连接的系统名:

          "jdbc:as400:"

     

            例二:URL只给出系统名

          Connection c  = DriverManager.getConnection("jdbc:as400://mySystem");

     

            例三:URL给出系统名,且给出缺省的Schema

          Connection c2 = DriverManager.getConnection("jdbc:as400://mySys2/mySchema");

     

    例四:连接AS/400 数据库,且使用java.util.Properties 定义更多的JDBC 连接属性。

         // Create a properties object.

         Properties p = new Properties();

         // Set the properties for the connection.

         p.put("naming", "sql");

         p.put("errors", "full");

         // Connect using the properties object.

         Connection c = DriverManager.getConnection("jdbc:as400://mySystem",p);

     

    例五:连接AS/400数据库,并且给出URL的相关属性.

         // Connect using properties. The properties are set on the URL

         // instead of through a properties object.

         Connection c = DriverManager.getConnection( "jdbc:as400://mySystem;naming=sql;errors=full");

     

    例六:连接AS/400数据库且给出用户名与口令

         // Connect using properties on the URL and specifying a user ID and password

         Connection c = DriverManager.getConnection(

                            "jdbc:as400://mySystem;naming=sql;errors=full",

                            "auser", "apassword");

     

    例七:关闭数据库连接

     使用close() 方法将连接关闭,如 c.close();

     

    (责任编辑:artmanager)
    [推荐给朋友] [显示打印版本]

      相关文章
      相关评论

    您的姓名:
    评论内容:
     
    设为首页 | 加入收藏 | 联系我们 | 友情链接 | 管理登录
    copyright by 新儒AS/400家园 站长:山人
    Power by 9466Aricle