免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: fh2001
打印 上一主题 下一主题

原创:用JDBC访问AS/400数据- 配置与JDBC编程要点 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2004-06-14 16:54 |只看该作者

原创:用JDBC访问AS/400数据- 配置与JDBC编程要点

内容详细,谢谢了。

论坛徽章:
0
12 [报告]
发表于 2004-11-08 21:10 |只看该作者

原创:用JDBC访问AS/400数据- 配置与JDBC编程要点

那里可以得到Jdbc驱动呀,急急!

论坛徽章:
0
13 [报告]
发表于 2004-11-08 21:50 |只看该作者

原创:用JDBC访问AS/400数据- 配置与JDBC编程要点

我怎么找不到jt400.zip呀,我的Client Access 是英文版权所5.1,在安装显示AS/400 Toolbox for Java已安装,请那位高手指点,谢谢.

论坛徽章:
0
14 [报告]
发表于 2004-11-09 09:15 |只看该作者

原创:用JDBC访问AS/400数据- 配置与JDBC编程要点

得仔细看看.

论坛徽章:
0
15 [报告]
发表于 2004-11-09 09:52 |只看该作者

原创:用JDBC访问AS/400数据- 配置与JDBC编程要点

[quote]原帖由 "mario663"]我怎么找不到jt400.zip呀,我的Client Access 是英文版权所5.1,在安装显示AS/400 Toolbox for Java已安装,请那位高手指点,谢谢.[/quote 发表:

到目录"C:\Program Files\IBM\Client Access\jt400\lib\jt400.jar"中看一看,我的C/A是安装在C盘上的!

另外,请教楼主一问题,我用JAVA写了一个测试的小程序
代码如下:

  1. import java.io.*;
  2. import java.util.*;
  3. import com.ibm.as400.access.*;
  4. public class  CommandCall extends Object{
  5.         public static void main(String[] parmeters){
  6.                 //Created a reader to get input from the user
  7.                 BufferedReader inputStream = new BufferedReader(new InputStreamReader(System.in),1);
  8.                 //Declare varialbes to hold the system name and the command to run
  9.                 String systemString = null;
  10.                 String commandString = null;
  11.                
  12.                 System.out.println("");
  13.                 //Get the system name and the command to run from the user
  14.                 try{
  15.                         System.out.print("System name:");
  16.                         systemString = inputStream.readLine();
  17.                 }
  18.                 catch (Exception e){};
  19.                 System.out.println("");
  20.                 //Create an as400 object.This is the system we send the command to
  21.                 AS400 as400 = new AS400(systemString);
  22.                 //Create a command call object specifying the server that will receive the command
  23.                 CommandCall command = new CommandCall(as400);
  24.                 //Run the command
  25.                 try{
  26.                         if (command.run(commandString))
  27.                                 System.out.print("Command successful");
  28.                         else
  29.                                 System.out.print("Command failed");
  30.                        
  31.                 //If messeage were produced from the command,print them
  32.                 AS400Messeage[] messeageList = command.getMesseageList();
  33.                 if (messeageList.length>;0){
  34.                         System.out.println(",messeage from the command:");
  35.                         System.out.print("");
  36.                 }
  37.                 for (int i=0;i<messeageList.length ;i++ ){
  38.                         System.out.print(messeageList[i].getID());
  39.                         System.out.print(":");
  40.                         System.out.print(messeageList[i].getText());
  41.                 }
  42.                 }
  43.                 catch (Exception e){
  44.                 System.out.println("Command" + command.getCommand() + "didn't run!");
  45.                 }
  46.                 System.exit(0);
  47.         }
  48. }

复制代码


以下是报错信息:
  1. ---------- javac ----------
  2. CommandCall.java:23: cannot resolve symbol
  3. symbol  : constructor CommandCall (com.ibm.as400.access.AS400)
  4. location: class CommandCall
  5.       CommandCall command = new CommandCall(as400);
  6.                                       ^
  7. CommandCall.java:26: cannot resolve symbol
  8. symbol  : method run (java.lang.String)
  9. location: class CommandCall
  10.          if (command.run(commandString))
  11.                                    ^
  12. CommandCall.java:32: cannot resolve symbol
  13. symbol  : class AS400Messeage
  14. location: class CommandCall
  15.       AS400Messeage[] messeageList = command.getMesseageList();
  16.                 ^
  17. CommandCall.java:32: cannot resolve symbol
  18. symbol  : method getMesseageList ()
  19. location: class CommandCall
  20.       AS400Messeage[] messeageList = command.getMesseageList();
  21.                                                       ^
  22. CommandCall.java:44: cannot resolve symbol
  23. symbol  : method getCommand ()
  24. location: class CommandCall
  25.       System.out.println("Command" + command.getCommand() + "didn't run!");
  26.                                                       ^
  27. 5 errors

  28. Output completed (5 sec consumed) - Normal Termination
复制代码

论坛徽章:
0
16 [报告]
发表于 2004-11-09 10:06 |只看该作者

原创:用JDBC访问AS/400数据- 配置与JDBC编程要点

ding....

论坛徽章:
0
17 [报告]
发表于 2007-04-13 10:42 |只看该作者
尽管来的太晚了,还是顶一下,都过了三年了

论坛徽章:
0
18 [报告]
发表于 2007-04-16 11:38 |只看该作者

回复 17楼 leojing 的帖子

不用这个,但值得一顶

论坛徽章:
0
19 [报告]
发表于 2007-10-05 11:29 |只看该作者
老大,提示找不到package com.ibm.as400.access.AS400JDBCDriver 啊 怎么办

论坛徽章:
0
20 [报告]
发表于 2009-08-07 14:47 |只看该作者

哈哈,今天刚刚试过,确实可以用JT400.jar实现连接

// 访问AS400的类
package UseBean;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AccessDB2 {
       
        public static Connection getConnection()
    {               
        try{
            DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
            }
        catch (Exception e) {
            System.out.println("There was an error...");
            e.printStackTrace();
             return null;
            }

        try {
                Class.forName("com.ibm.as400.access.AS400JDBCDriver");
                return DriverManager.getConnection( "jdbc:as400://192.168.130.30/s6528d3b", "lifight1", "lifight1" );
             }
         catch (Exception e) {
             System.out.println("There was an error...");
             e.printStackTrace();
             return null;
            }
    }
   
   
    public static void releaseConnection( Connection conn, java.sql.Statement st, ResultSet rs )
    {
        if( rs!=null )
        {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        
        if( st!=null )
        {
            try {
                st.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        
        if( conn!=null )
        {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
//调用访问类,执行一条SQL语句
package UseBean;
import java.sql.*;

public class ADO {       
       
        public String getData()
        {
                String output="";
                String selectSQL = "Select ID,Name from DBTEST.TEST";
                Connection oCon = null;
                Statement stmt = null;
                ResultSet rs = null;
                try {
                   oCon=AccessDB2.getConnection();
                   stmt = oCon.createStatement();
                   rs = stmt.executeQuery(selectSQL);
                   while (rs.next()){
                          output = output+String.valueOf(rs.getInt(1))+":"+rs.getString(2)+"<br>";
                   }
                }
                catch(SQLException ex){
                        output="wrong";                       
                }
               
                AccessDB2.releaseConnection(oCon, stmt, rs);
               
                return output;               
        }
}
//JSP页面显示调用查询结果
<jsp:useBean id='ADO' class="UseBean.ADO" scope="page"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>   
    <title>My JSP 'index.jsp' starting page</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">   
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
  </head>
  <body>
<%
String s = ADO.getData();
out.print(s);
%>
<br>
  </body>
</html>
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP