与AS400的JDBC连接创建Nullpointer

时间:2014-09-30 08:52:54

标签: java jdbc ibm-midrange

我正在研究在AS400服务器上运行的java应用程序。

    try {
        Class.forName("com.ibm.as400.access.AS400JDBCDriver");
        String doTrace = AppProp.getInstance().getProperty("trace.enabled");
        if("true".equals(doTrace)){
            Trace.setTraceAllOn(true);
            String tracefile = AppProp.getInstance().getProperty("trace.file");
            new File(tracefile).createNewFile();
            Trace.setFileName(tracefile);
            Trace.setTraceOn(true);
            log.warn("Trace Enabled");
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new ExceptionInInitializerError(e);

    }

和这个

    try {

        if ("true".equals(local)) {
            user = "*CURRENT";
            password = "*CURRENT";
        }
        connection = DriverManager.getConnection(url, user, password);

    } finally{
        //do something here...
    }

使用url beeing jdbc:as400://10.65.1.31/QSYS.LIB

在连接到AS400的Windows服务器上运行时工作正常,但在AS400本地运行时我得到例外:

at com.df.info2000.as400Worker.AS400SQLConnection.getConnection(AS400SQLConnection.java:66)
    at com.df.info2000.as400Worker.AS400FileAccess.initConnection(AS400FileAccess.java:62)
    at com.df.info2000.as400Worker.AS400FileAccess.<init>(AS400FileAccess.java:50)
    at com.df.info2000.as400Worker.AS400FileIterator.<init>(AS400FileIterator.java:23)
    at com.df.info2000.wscom.WSCOMTransferFileThradsafe.connectAS400Iterator(WSCOMTransferFileThradsafe.java:674)
    at com.df.info2000.wscom.WSCOMTransferFileThradsafe.initialize(WSCOMTransferFileThradsafe.java:132)
    ... 1 more
Caused by: java.lang.NullPointerException
    at java.lang.Throwable.<init>(Throwable.java:181)
    at java.lang.Exception.<init>(Exception.java:29)
    at java.lang.RuntimeException.<init>(RuntimeException.java:32)
    at java.lang.NullPointerException.<init>(NullPointerException.java:36)
    at com.ibm.as400.access.SocketContainerUnix.getInputStream(SocketContainerUnix.java:65)
    at com.ibm.as400.access.AS400ImplRemote.signonConnect(AS400ImplRemote.java:1834)
    at com.ibm.as400.access.AS400ImplRemote.getConnection(AS400ImplRemote.java:957)
    at com.ibm.as400.access.AS400ImplRemote.connect(AS400ImplRemote.java:392)
    at com.ibm.as400.access.AS400.connectService(AS400.java:822)
    at com.ibm.as400.access.AS400JDBCConnection.setProperties(AS400JDBCConnection.java:2764)
    at com.ibm.as400.access.AS400JDBCDriver.prepareConnection(AS400JDBCDriver.java:1040)
    at com.ibm.as400.access.AS400JDBCDriver.initializeConnection(AS400JDBCDriver.java:931)
    at com.ibm.as400.access.AS400JDBCDriver.connect(AS400JDBCDriver.java:355)
    at java.sql.DriverManager.getConnection(DriverManager.java:525)
    at java.sql.DriverManager.getConnection(DriverManager.java:171)
    at com.df.info2000.as400Worker.AS400SQLConnection.getConnection(AS400SQLConnection.java:51)
    ... 6 more 

从跟踪日志中我现在发现了这个:

Thread[Thread-0,5,main]  Wed Oct 01 09:17:51 CEST 2014  Error retrieving GSSToken:
org.ietf.jgss.GSSException, major code: 11, minor code: 0
major string: General failure, unspecified at GSSAPI level
minor string: Error: com.ibm.security.krb5.KrbException, status code: 0
message: java.security.PrivilegedActionException: java.io.FileNotFoundException: No such path or directory. /etc/krb5/krb5.conf
at java.lang.Throwable.<init>(Throwable.java:181)
at java.lang.Exception.<init>(Exception.java:29)
at org.ietf.jgss.GSSException.<init>(GSSException.java:181)
at com.ibm.security.jgss.i18n.I18NException.throwGSSException(I18NException.java:5)
at com.ibm.security.jgss.mech.krb5.bb.b(bb.java:32)
at com.ibm.security.jgss.mech.krb5.bb.a(bb.java:154)
at com.ibm.security.jgss.mech.krb5.bb.<init>(bb.java:36)
at com.ibm.security.jgss.mech.krb5.Krb5MechFactory.getNameElement(Krb5MechFactory.java:44)
at com.ibm.security.jgss.GSSManagerImpl.a(GSSManagerImpl.java:19)
at com.ibm.security.jgss.GSSNameImpl.a(GSSNameImpl.java:17)
at com.ibm.security.jgss.GSSNameImpl.canonicalize(GSSNameImpl.java:0)
at com.ibm.security.jgss.GSSNameImpl.<init>(GSSNameImpl.java:173)
at com.ibm.security.jgss.GSSManagerImpl.createName(GSSManagerImpl.java:14)
at com.ibm.as400.access.TokenManager.getGSSToken(TokenManager.java:35)
at com.ibm.as400.access.AS400.signon(AS400.java:3359)
at com.ibm.as400.access.AS400.connectService(AS400.java:821)
at com.ibm.as400.access.AS400JDBCConnection.setProperties(AS400JDBCConnection.java:2764)
at com.ibm.as400.access.AS400JDBCDriver.prepareConnection(AS400JDBCDriver.java:1040)
at com.ibm.as400.access.AS400JDBCDriver.initializeConnection(AS400JDBCDriver.java:931)
at com.ibm.as400.access.AS400JDBCDriver.connect(AS400JDBCDriver.java:355)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.df.info2000.as400Worker.AS400SQLConnection.getConnection(AS400SQLConnection.java:67)
at com.df.info2000.as400Worker.AS400FileAccess.initConnection(AS400FileAccess.java:62)
at com.df.info2000.as400Worker.AS400FileAccess.<init>(AS400FileAccess.java:50)
at com.df.info2000.as400Worker.AS400FileIterator.<init>(AS400FileIterator.java:23)
at com.df.info2000.wscom.WSCOMTransferFileThradsafe.connectAS400Iterator(WSCOMTransferFileThradsafe.java:674)
at com.df.info2000.wscom.WSCOMTransferFileThradsafe.initialize(WSCOMTransferFileThradsafe.java:132)
at com.df.info2000.wscom.MainExtract.main(MainExtract.java:62)
Thread[Thread-0,5,main]  Wed Oct 01 09:17:51 CEST 2014  Signing-on without prompting...
Thread[Thread-0,5,main]  Wed Oct 01 09:17:51 CEST 2014  Current userID in EBCDIC: 
D3 C5 C3 D4 D6 C8 40 40 40 40 
Thread[Thread-0,5,main]  Wed Oct 01 09:17:51 CEST 2014  Current userID: 'LECMOH'
Thread[Thread-0,5,main]  Wed Oct 01 09:17:51 CEST 2014  Current userID in EBCDIC: 
D3 C5 C3 D4 D6 C8 40 40 40 40 
Thread[Thread-0,5,main]  Wed Oct 01 09:17:51 CEST 2014  Current userID: 'LECMOH'
Thread[Thread-0,5,main]  Wed Oct 01 09:17:51 CEST 2014  Sign-on completed.
Thread[Thread-0,5,main]  Wed Oct 01 09:17:51 CEST 2014  Service disconnected implementation: as-signon
Thread[Thread-0,5,main]  Wed Oct 01 09:17:51 CEST 2014  Establishing connection to server: as-database
Thread[Thread-0,5,main]  Wed Oct 01 09:17:51 CEST 2014  Starting a local socket to as-signon

你能看出可能出现的问题吗?

我们正在运行AS400版本R610

由于某种原因,该程序正在尝试使用Kerberos对用户进行身份验证 - 即使我提供了参数AuthenticationMethod = client

现在我正在尝试启动并运行一些远程调试,因此我们将CL命令修改为:

 RUNJVA     CLASS('com.df.info2000.wscom.MainExtract')    
                    CLASSPATH('/DFWSCOM/config/')               
                    OPTIMIZE(*JIT) INTERPRET(*JIT)              
                    PROP(                                       
    (os400.xrun.option 'jdwp:transport=dt_socket,address=8000,  
    server=y,suspend=y')                                        
                     (java.security.krb5.conf                   
      '/QIBM/ProdData/OS400/NetworkAuthentication/krb5.conf')   
                                           (java.ext.dirs    
                    '/DFWSCOM/lib/')) GCHINL(240000000)         
                    GCHMAX(*NOMAX) JOB(WSCOVFC) OUTPUT(*NONE)     

但它以此消息结束: 信息 。 。 。 。 :在* SRVPGM的JVM_OnLoad处理期间发生错误   JDWP15。错误代码是3.
Årsag。 。 。 。 。 :JVM_OnLoad函数未完成* SRVPGM
  JDWP15因错误代码3.错误代码定义如下:1 -   JVM无法找到服务程序。 2 - JVM无法做到   激活服务程序。 3 - JVM无法找到   JVM_OnLoad函数。 4 - 从JVM_OnLoad

返回错误代码0

我的AS400家伙说它不懂os400.xrun.option - 谁能看到我们做错了什么?

嗯 - 现在我们已经将程序移动到prod环境以查看它是否会在那里运行 - 并且神奇地会这样,所以我们的测试AS400出了问题。所以现在它在prod中工作,我们在测试服务器上遇到问题......

2 个答案:

答案 0 :(得分:0)

实际上我不知道你到目前为止尝试了什么但是只需遵循这个代码并验证自己并得到解决...... !!!

 Connection con = null;  

    try {  
          Class.forName("com.ibm.as400.access.AS400JDBCDriver);  
    } catch(ClassNotFoundException e) {  
          System.out.println(e);  
          System.exit(0);  
    }  


    try {  
          con = DriverManager.getConnection("jdbc:as400://yourserver", "yourUserId", "yourPassword");  

          Statement stmt = con.createStatement();  

          ResultSet rs = stmt.executeQuery("SELECT * FROM YOURLIB.YOUR_PF_FILE");  

          while (rs.next()) {  

                  String field1 = rs.getString(1);  
                  String field2 = rs.getString("fieldname");  

                  .....  
          }  catch(Exception e) {  

              .....  

          }   

我希望这会对你有所帮助

答案 1 :(得分:0)

看起来你有几个问题。

  1. 您需要升级jt400.jar文件,因为跟踪点似乎与最新的jt400.jar跟踪点不匹配。最新的V6R1 PTF是SI53962和SI53963。

  2. 您应该使用空指针而不是* CURRENT。允许使用* CURRENT是旧版JTOpen的安全风险,并且已被禁止使用。因此,您的代码应如下所示。

    if ("true".equals(local)) {
        user = null;
        password = null;
    }