2016-09-08 66 views
0

我有一個存儲過程,我想在Java中調用過程並用作Web服務。我一直在進行多個操作,「deger」返回單個值,如何返回多個值?快樂編碼如何在Java中返回多個值(插入sp)?

My procedure : 



CREATE OR REPLACE PROCEDURE thkk_kaydet(
      p_no IN TEMP_TAHAKKUK_AG.ABONENO%TYPE, 
      p_tplm IN TEMP_TAHAKKUK_AG.TOPLAM%TYPE) 
    IS 
    BEGIN 
     INSERT INTO TEMP_TAHAKKUK_AG ("ABONENO", "TOPLAM") 
     VALUES (p_no, p_tplm); 
     COMMIT; 
    END; 

我的Web服務類 - 與連接方法

import javax.jws.WebService; 
    import java.sql.CallableStatement; 
    import java.sql.Connection; 
    import java.sql.DriverManager; 
    import java.sql.ResultSet; 
    import java.sql.SQLException; 
    import java.sql.Statement; 
    import javax.jws.WebMethod; 



    @WebService 
    public class WSWebLogic { 
     public static Connection getConnection_test() throws Exception { 
      String driver = "oracle.jdbc.driver.OracleDriver"; 
      String url = "jdbc:oracle:thin:@00.00.0.00:1521:TEST"; 
      String username = "username"; 
      String password = "password"; 
      Class.forName(driver); // load Oracle driver 
      Connection conn = DriverManager.getConnection(url, username, password); 
      return conn; 
      } 


     @WebMethod 
      public static void get_tatil (@WebParam(name = "arg0") String p_no, int p_tplm) { 
        Connection conn=null; 
        Statement stmt=null; 
        ResultSet rs=null; 
        String deger=null; 
        try { 
         conn = getConnection_test(); 
         String query = "BEGIN" + 
             "thkk_kaydet('" + 
          p_no + 
           "','" + 
            p_tplm + 
             "');" + 
           "END"; 
         stmt = conn.createStatement(); 
         rs = stmt.executeQuery(query); 
         while (rs.next()) { 
         deger = rs.getString(1);       
         }   
        } catch (Exception e) { 
         System.err.println(e.getMessage()); 
        } finally { 
         try { 
         rs.close(); 
         stmt.close(); 
         conn.close(); 
         } catch (SQLException e) { 
          System.err.println(e.getMessage()); 
        }   
        }     
      } 
    } 

回答

0

申報返回列表或字符串數​​組。

您可以使用目錄字符串是這樣的:

List<String> degerList = new ArrayList(); 

當你迭代在陣列上,保持備案表作爲

 degerList.add(deger); 

,並返回該degerList

更改返回類型爲List<String>而不是void

+0

謝謝,但我需要通過java web服務插入到oracle(p_no和p_tplm列)中,它們必須分別作爲p_no和p_tplm列。 –

+0

返回爲JSON,解析JSON並插入其他數據庫@ M.Telceken –

+0

我添加爲答案,你能幫我嗎? Tnx很多@Danyal Sandeelo –

0

當我編寫函數而不是程序時,它編譯。

CREATE OR REPLACE function ilce_gtr 
(
    p_ilkodu number 
) 
RETURN VARCHAR2 AS 
p_geridonen varchar2(1000); 
begin 
for rec in(SELECT ADI FROM ILCE WHERE Y_IL=p_ilkodu) 
loop 
p_geridonen := p_geridonen || '|' || rec.ADI; 
end loop; 
return p_geridonen; 
end; 
/

然後我通過web方法創建了xml,它很成功。

@WebMethod 
     public String get_ilce (int p_ilkodu) { 

      Statement stmt=null; 
      ResultSet rs=null; 
      Connection conn=null; 
      String deger=null; 

      try { 
       conn= getConnection_test(); 
       String query = "SELECT ILCE_GTR('" + p_ilkodu + "') FROM DUAL"; 
       stmt = conn.createStatement(); 
       rs = stmt.executeQuery(query); 
       while (rs.next()) { 
       deger = rs.getString(1);       
       }   

      } catch (Exception e) { 
       return "hata"; 
      } finally { 
       try { 
       rs.close(); 
       stmt.close(); 
       conn.close(); 
       } catch (SQLException e) { 
       return "hata"; 
       }   
      }    
      return deger; 
     } 

使用web服務插入到oracle數據庫,我該怎麼辦?謝謝你