2010-08-31 74 views
0

我正試圖讓存儲過程能夠從Lotus Notes中的java代理程序調用。在將數據移入和移出db2表時,我已經能夠使這些類型的代理正常工作,並且我還能夠使用與我相同的用戶名/密碼從Iseries Navigator運行存儲過程使用這個代理。但是,當我嘗試運行代理時,它給我一個錯誤。這是我的Java代碼:通過Notes Java代理程序存儲過程

import java.io.File; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.net.URL; 
import java.sql.CallableStatement; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.SQLException; 
import java.sql.Types; 
import java.util.Properties; 
import java.util.Vector; 
import com.ibm.as400.access.AS400JDBCDriver; 
import lotus.domino.Agent; 
import lotus.domino.AgentBase; 
import lotus.domino.AgentContext; 
import lotus.domino.Database; 
import lotus.domino.Document; 
import lotus.domino.NotesException; 
import lotus.domino.Session; 

public class NotesUpdateAS400Control 
extends AgentBase { 

    private Session session = null; 
    private Agent agt = null; 
    private Database db = null; 
    private Document doc = null; 
    private Vector allObjects = new Vector(); 
    // 
    private final String INIT_FILE_NAME = "AgentInitProps.properties"; 
    //set the values we will use to log in 
    private String dbUser = null; 
    private String dbPswd = null; 
    private String dbHost = null; 
    // 

    public NotesUpdateAS400Control() { 
     super(); 
    } 

    private void init() { 
     try { 
      // Gain access to the current document 
      session = getSession(); 
      AgentContext agentContext = session.getAgentContext(); 
      allObjects.addElement(agentContext); 
      agt = agentContext.getCurrentAgent(); 
      db = agentContext.getCurrentDatabase(); 
      allObjects.addElement(db); 
      String tempNoteID = agt.getParameterDocID(); 
      doc = db.getDocumentByID(tempNoteID); 
      allObjects.addElement(doc); 
     } catch (NotesException notesEx) { 
      System.out.println("buildPreparedStatement NotesException: " + notesEx); 
      notesEx.printStackTrace(System.out); 
     } 
    } 

    // 
    protected Connection buildConnection() throws NotesException { 
     Connection con = null; 

     // Get AS/400 Connection 
     try { 
      URL url = ClassLoader.getSystemResource("."); 
      File initFile = new File(url.getFile() + INIT_FILE_NAME); 
      FileInputStream fis = new FileInputStream(initFile); 
      Properties props = new Properties(); 
      props.load(fis); 
      dbUser = props.getProperty("dbUser"); 
      dbPswd = props.getProperty("dbPswd"); 
      dbHost = props.getProperty("dbHost"); 
      fis.close(); 

      // Register AS/400 Driver 
      DriverManager.registerDriver(new AS400JDBCDriver()); 
      con = DriverManager.getConnection("jdbc:as400://" + dbHost, dbUser, dbPswd); 
      doc.save(); 
     } catch (SQLException sqlEx) { 
      System.out.println("buildConnection SQLException: " + sqlEx); 
      sqlEx.printStackTrace(System.out); 
      doc.save(); 
     } catch (IOException ioe) { 
      ioe.printStackTrace(); 
     } catch (NotesException notesEx) { 
      System.out.println("buildConnection NotesException: " + notesEx); 
      doc.save(); 
      notesEx.printStackTrace(System.out); 
     } 
     return con; 
    } 
    // 

    public void NotesMain() { 
     init(); 
     try { 
      System.out.println("Test of Stored Procedure Agent"); 

      CallableStatement pspmt = null; 

      try { 
       con = this.buildConnection(); 
       if (con != null) { 
        pspmt = con.prepareCall("CALL DB2ADMIN.MYZIPTOZIP(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); 
        System.out.println("Test"); 
        pspmt.clearParameters(); 
        pspmt.registerOutParameter(7, Types.CHAR); 
        pspmt.registerOutParameter(8, Types.CHAR); 
        pspmt.registerOutParameter(9, Types.DECIMAL); 
        pspmt.registerOutParameter(10, Types.CHAR); 
        pspmt.setString(1, "NASHVILLE"); 
        pspmt.setString(2, "TN"); 
        pspmt.setString(3, "37202"); 
        pspmt.setString(4, "COOKEVILLE"); 
        pspmt.setString(5, "TN"); 
        pspmt.setString(6, "38501"); 

        pspmt.execute(); 
        System.out.println("OutParam7 " + pspmt.getString(7)); 
        String value1 = pspmt.getString(7); 
        String value2 = pspmt.getString(8); 
        String value3 = pspmt.getBigDecimal(9).setScale(0).toString(); 
        String value4 = pspmt.getString(10); 

        doc.replaceItemValue("test1", value1.trim()); 
        System.out.println("Test " + value1.trim()); 
        doc.replaceItemValue("test2", value2.trim()); 
        doc.replaceItemValue("test3", value3.trim()); 
        doc.replaceItemValue("test4", value4.trim()); 


        Vector vals = new Vector(); 

        vals.addElement(pspmt.getString(7)); 
        vals.addElement(pspmt.getString(8)); 
        vals.addElement(pspmt.getBigDecimal(9).setScale(0).toString()); 
        vals.addElement(pspmt.getString(10)); 

        System.out.println("Zip to zip value object : " + vals.toString()); 


       } 
      } catch (SQLException sqlEx) { 
       System.out.println("executeUpdate SQLException: " + sqlEx); 
       sqlEx.printStackTrace(System.out); 
      } catch (NotesException notesEx) { 
       System.out.println("executeUpdate NotesException: " + notesEx); 
       notesEx.printStackTrace(System.out); 
      } finally { 
       try { 
        if (pspmt != null) { 
         pspmt.close(); 
         pspmt = null; 
        } // end of if 
        if (con != null) { 
         con.close(); 
         con = null; 
        } // end of if 
       } catch (SQLException sqlEx) { 
        System.out.println("close con/pspmt SQLException: " + sqlEx); 
        sqlEx.printStackTrace(System.out); 
       } 
      } 
      // 
      doc.save(); 
      doc.recycle(); // recycle the one we're done with 
      agt.recycle(); 
      db.recycle(); 
     } // end of try 
     catch (Exception e) { 
      System.out.println(e); 
      e.printStackTrace(System.out); 
     } // end of catch 
     finally { 
      try { 
       session.recycle(allObjects); 
       session.recycle(); 
       //session = null; 
       System.runFinalization(); 
      } // end of try 
      catch (Exception e) { 
       System.out.println(e); 
       e.printStackTrace(System.out); 
      } // end of catch 
     } // end of catch 
     System.gc(); 
     long memAfter = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); 
     System.out.println("NotesUpdateAS400 agent completed. Current JVM Heap Size : " + memAfter); 


    } // end of notes main 
} 

然而,當我運行此代碼,我得到以下錯誤在控制檯:

[0774:0025-0BD0] 08/31/2010 09:11:03 AM 0 Transactions/Minute, 0 Notes Users[0774:009C-032C] 08/31/2010 09:11:41 A 
M Agent printing: Test of Stored Procedure Agent 
[0774:009C-032C] 08/31/2010 09:11:42 AM Agent printing: executeUpdate SQLException: java.sql.SQLException: [SQL044 
0] Routine MYZIPTOZIP in DB2ADMIN not found with specified parameters. 
[0774:009C-032C] 08/31/2010 09:11:42 AM Agent printing: java.sql.SQLException: [SQL0440] Routine MYZIPTOZIP in DB2 
ADMIN not found with specified parameters. 
[0774:009C-032C] 08/31/2010 09:11:42 AM Agent printing:  at com.ibm.as400.access.JDError.throwSQLException(J 
DError.java:646) 
[0774:009C-032C] 08/31/2010 09:11:42 AM Agent printing:  at com.ibm.as400.access.JDError.throwSQLException(J 
DError.java:617) 
[0774:009C-032C] 08/31/2010 09:11:42 AM Agent printing:  at com.ibm.as400.access.AS400JDBCStatement.commonPr 
epare(AS400JDBCStatement.java:1578) 
[0774:009C-032C] 08/31/2010 09:11:42 AM Agent printing:  at com.ibm.as400.access.AS400JDBCPreparedStatement. 
<init>(AS400JDBCPreparedStatement.java:227) 
[0774:009C-032C] 08/31/2010 09:11:42 AM Agent printing:  at com.ibm.as400.access.AS400JDBCCallableStatement. 
<init>(AS400JDBCCallableStatement.java:106) 
[0774:009C-032C] 08/31/2010 09:11:42 AM Agent printing:  at com.ibm.as400.access.AS400JDBCConnection.prepare 
Call(AS400JDBCConnection.java:1808) 
[0774:009C-032C] 08/31/2010 09:11:42 AM Agent printing:  at com.ibm.as400.access.AS400JDBCConnection.prepare 
Call(AS400JDBCConnection.java:1709) 
[0774:009C-032C] 08/31/2010 09:11:42 AM Agent printing:  at com.averitt.notesProcessing.NotesUpdateAS400Cont 
rol.NotesMain(NotesUpdateAS400Control.java:110) 
[0774:009C-032C] 08/31/2010 09:11:42 AM Agent printing:  at lotus.domino.AgentBase.runNotes(Unknown Source) 
[0774:009C-032C] 08/31/2010 09:11:42 AM Agent printing:  at lotus.domino.NotesThread.run(Unknown Source) 
[0774:009C-032C] 08/31/2010 09:11:42 AM Agent printing: NCC Forms NotesUpdateAS400 agent completed. Current JVM He 
ap Size : 5927920 

同樣,存儲過程工作正常操作導航和調用時通過我們通常使用它的J2EE應用程序,使用我在此使用的相同用戶名。 Java代理在我選擇或插入其他程序時工作正常。有人有任何想法嗎?

感謝,

回答

2

您的代碼難以閱讀,但是存儲的過程似乎需要10個參數,而你得到的錯誤是不言自明:不管它是你最終傳遞到iSeries,它的不是對程序的有效調用。換句話說,問題不在於Domino的Java實現本身,而在於你所做的調用(就像你一樣,我可以確認AS400存儲過程在Java中工作得很好)。

的罪魁禍首在情況是這樣的:

  1. 你要註冊正確的參數的數據類型?
  2. 註冊參數時,您是否設置了合適的比例?
  3. 設置輸入值時,數據類型是否正確?