Java Web 服务调用目标异常
Java WebServices InvocationTargetException
当我尝试向我的 Web 服务 AddEmployee 输入任何参数时出现此异常
基本上我想做的只是将一些数据插入 MS Access 数据库,我认为最好的做法是让 java class 包含函数和 Web 服务使用适当的参数调用这些函数,我有一个单独的 Web 服务来建立与数据库的连接
我试过不带参数,带虚拟参数,没有参数和空参数,问题出在网络服务本身,函数工作得很好,函数和数据库之间没有数据类型不匹配
网络服务代码
@WebMethod(operationName="AddEmployee")
public String NouveauEmployee(@WebParam (name="Prenom Nom")String Nom,@WebParam(name="Matricule")Float Mat,@WebParam(name="Code Service")Float CodeSrv,@WebParam(name="Service")String Service,@WebParam(name="Code Emploi")String CodeEmp,@WebParam(name="Groupe Professionnelle")String GrpPro) {
return EM.functions.NvEmploye("Marouane Mhaiti",1254,110,"OIS/C/M","W7845","OE/GC");
}
函数代码
public static String NvEmploye (String Nom,Integer Matricule,Integer CodeSrv,String Service,String CodeEmp,String GrpPro) {
Connection con=conout;
Statement sqlStatement;
try {
sqlStatement = con.createStatement();
} catch (SQLException e) {
return "Error when creating statement";
}
String commandString="insert into Personel ([Nom Prenom],[Matricule],[Code Service],[Service],[Code emploi],[Groupe professionnelle]) values";
commandString+="('"+Nom+"',"+Matricule+","+CodeSrv+",'"+Service+"','"+CodeEmp+"','"+GrpPro+"')";
try {
sqlStatement.execute(commandString);
return "Employee added";
} catch (SQLException e) {
return "error when executing statement";
}
}
这有效
@WebMethod(operationName="AddEmployee")
public String NouveauEmployee() {
return EM.functions.NvEmploye("Marouane Mhaiti",1254,110,"OIS/C/M","W7845","OE/GC");
}
我在这里期待的是它从函数中弹出 "Employee Added" 消息,而不是给出
WS00041:服务调用引发异常,消息为:null;有关详细信息,请参阅服务器日志
异常详细信息:java.lang.reflect.InvocationTargetException
基本上输入任何参数都会导致此异常,我确定错误出在 Web 服务上,因为它没有显示 throw 子句中的 "Error when XXX"
PS : 无需审查此处显示的任何数据都是编造的
没关系,我找到它的人,基本上只是在 NetBeans 上制作设计功能,我认为问题是我有一些参数声明为 Integer 而不是 int,不确定这是否是问题的根源,但它当我使用NetBeans提供的功能时解决了。
当我尝试向我的 Web 服务 AddEmployee 输入任何参数时出现此异常
基本上我想做的只是将一些数据插入 MS Access 数据库,我认为最好的做法是让 java class 包含函数和 Web 服务使用适当的参数调用这些函数,我有一个单独的 Web 服务来建立与数据库的连接 我试过不带参数,带虚拟参数,没有参数和空参数,问题出在网络服务本身,函数工作得很好,函数和数据库之间没有数据类型不匹配
网络服务代码
@WebMethod(operationName="AddEmployee")
public String NouveauEmployee(@WebParam (name="Prenom Nom")String Nom,@WebParam(name="Matricule")Float Mat,@WebParam(name="Code Service")Float CodeSrv,@WebParam(name="Service")String Service,@WebParam(name="Code Emploi")String CodeEmp,@WebParam(name="Groupe Professionnelle")String GrpPro) {
return EM.functions.NvEmploye("Marouane Mhaiti",1254,110,"OIS/C/M","W7845","OE/GC");
}
函数代码
public static String NvEmploye (String Nom,Integer Matricule,Integer CodeSrv,String Service,String CodeEmp,String GrpPro) {
Connection con=conout;
Statement sqlStatement;
try {
sqlStatement = con.createStatement();
} catch (SQLException e) {
return "Error when creating statement";
}
String commandString="insert into Personel ([Nom Prenom],[Matricule],[Code Service],[Service],[Code emploi],[Groupe professionnelle]) values";
commandString+="('"+Nom+"',"+Matricule+","+CodeSrv+",'"+Service+"','"+CodeEmp+"','"+GrpPro+"')";
try {
sqlStatement.execute(commandString);
return "Employee added";
} catch (SQLException e) {
return "error when executing statement";
}
}
这有效
@WebMethod(operationName="AddEmployee")
public String NouveauEmployee() {
return EM.functions.NvEmploye("Marouane Mhaiti",1254,110,"OIS/C/M","W7845","OE/GC");
}
我在这里期待的是它从函数中弹出 "Employee Added" 消息,而不是给出
WS00041:服务调用引发异常,消息为:null;有关详细信息,请参阅服务器日志 异常详细信息:java.lang.reflect.InvocationTargetException
基本上输入任何参数都会导致此异常,我确定错误出在 Web 服务上,因为它没有显示 throw 子句中的 "Error when XXX"
PS : 无需审查此处显示的任何数据都是编造的
没关系,我找到它的人,基本上只是在 NetBeans 上制作设计功能,我认为问题是我有一些参数声明为 Integer 而不是 int,不确定这是否是问题的根源,但它当我使用NetBeans提供的功能时解决了。