到AS400的JDBC连接创建Nullpointer



我正在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为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=客户端

现在我正在尝试进行一些远程调试,所以我们将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)     

但它的结尾是这样的信息:消息……:JVM_OnLoad处理*SRVPGM期间出错JDWP15.错误代码为3。
Årsag……:*SRVPGM的JVM_OnLoad函数未完成
JDWP15,因为错误代码为3。错误代码定义如下:1-JVM无法定位服务程序。2-JVM无法激活服务程序。3-JVM无法定位
JVM_OnLoad函数。4-JVM_OnLoad 返回错误代码0

我的AS400负责人说它不理解os400.xrun.option——有人能看到我们做错了什么吗?

好吧,现在我们已经将程序移到prod环境中,看看它是否会在那里运行——神奇的是,它会运行,所以我们的测试AS400出现了问题。所以现在它在prod中工作,我们在测试服务器上处理这个问题。。。

事实上,我不知道你到目前为止尝试了什么,但只需遵循此代码并验证自己,就可以解决问题。。。!!!

 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. 您需要升级您的jt400.jar文件,因为跟踪点似乎与最新的jt404.jar跟踪点不匹配。V6R1的最新PTF是SI53962和SI53963。

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

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

相关内容

  • 没有找到相关文章

最新更新