我有一个存储过程,我想在Java中调用过程并用作Web服务。我已经进行了多次操作,“deger”返回单个值,如何返回多个值?快乐的编码
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;
我的网络服务类 - 使用连接方法
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 :(得分:0)
声明返回列表或字符串数组。
你可以使用这样的字符串列表:
List<String> degerList = new ArrayList();
当您遍历数组时,请继续将列表归档为
degerList.add(deger);
并返回此degerList
将返回类型更改为List<String>
而不是void
答案 1 :(得分: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数据库,我该怎么办?谢谢你