DB2 使用java存储过程,class要用Axis调用接口可以吗?,我将要用的jar(activation.jar、ant-1.8.2.jar、axis.jar、commons-discovery-0.2.jar、commons-logging-1.1.3.jar、jaxrpc.jar、log4j-1.2.15.jar、mail-1.4.jar、wsdl4j-1.6.3.jar)都打包到一个jar中,在调用时还是有错误
Java 程序:
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.xml.namespace.QName;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.message.MessageElement;
import org.apache.axis.message.SOAPHeaderElement;
public class DB2Java {
public static String writeLog(String name){
//appendMethodLog("C://work//log.txt",name);
String hh="";
try{
testSender("",name);
}catch(Exception e){
hh= e.getMessage();
appendMethodLog("C://work//log.txt",hh);
}
return name;
}
public static void appendMethodLog(String fileName, String content){
try {
FileWriter writer = new FileWriter(fileName, true);
writer.write(content);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// 关键接口数据已经删掉了
public static String testSender(String receivers, String msgSmsContent)throws Exception{
System.out.println("testSender");
String rtnXml = "";
String url = "";
Service service = new Service();
Call call;
call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(url));
call.removeAllParameters();
call.setOperationName();
call.addParameter("fromSystem", XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter("msgType", XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter("sendToId", XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter("sendAtTime", XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(XMLType.SOAP_STRING);
String fromSystem = "";
String msgType = "";
String sendToId = receivers;
String sendAtTime = "";
rtnXml = (String) call.invoke(new Object[] { fromSystem, msgType,
sendToId, sendAtTime });
System.out.println("OK");
return rtnXml;
}
}
DB2注册:
CALL sqlj.replace_jar( 'file:///D:/Program Files (x86)/IBM/SQLLIB/FUNCTION/DB2Java.jar', 'DB2Java' )
call sqlj.refresh_classes
创建方法:
create Function writeLog(name varchar(30))
returns varchar(70)
fenced
variant
no sql
external action
language java
parameter style java
external name 'DB2Java.writeLog'
db2diag.log错误:
java.lang.ExceptionInInitializerError
at java.lang.J9VMInternals.initialize(J9VMInternals.java:255)
at org.apache.axis.handlers.BasicHandler.(BasicHandler.java:43)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:233)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at org.apache.axis.client.Service.getAxisClient(Service.java:104)
at org.apache.axis.client.Service.(Service.java:113)