【发布时间】:2011-11-23 17:34:36
【问题描述】:
这段代码完全错误吗?我正在为一个 uni 项目制作web service。是否可以在 web service 方法中连接到数据库。
连接代码在标准 SE 项目中有效,但在 Web 服务中 NetBeans 不允许我部署项目,它说它无法创建 WSDL。
/* * 要更改此模板,请选择工具 |模板 * 并在编辑器中打开模板。 */ 包 org.me.calculator;
import com.mysql.jdbc.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;
/**
*
* @author ericman
*/
@WebService(serviceName = "CalculatorWS")
@ Stateless()
public class CalculatorWS {
/**
* Web service operation
*/
@WebMethod(operationName = "UppDateBook")
public String UppDateBook(@WebParam(name = "name") String name) throws SQLException {
//TODO write your implementation code here:
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/bookcatalog","ericman","ericman");
Statement stmt = (Statement) con.createStatement();
String insert = "INSERT INTO `bookcatalog`.`books` (`name`, `isbn`, `price`, `publisher`, `img`) VALUES ('BookOne', '12456789', '45', 'publisher', 'httpfile');";
int numUpdate = stmt.executeUpdate(insert);
stmt.close();
return null;
}
}
错误信息
严重:无法找到端点的适配器 警告:MEX0008:无法使用协议 SOAP_1_1 解析从位于 http://localhost:8080/WebSercviceOne/WebSercviceOne?WSDL/mex 的服务器返回的元数据。不断尝试。 信息:[错误] 服务器返回 HTTP 响应代码:405 用于 URL:http://localhost:8080/WebSercviceOne/WebSercviceOne?WSDL 读取WSDL文档失败:http://localhost:8080/WebSercviceOne/WebSercviceOne?WSDL,因为1)找不到文档; /2) 文件无法读取; 3) 文档的根元素不是 . INFO: [ERROR] failed.noservice=在提供的 WSDL(s) 中找不到 wsdl:service: 需要提供至少一个具有至少一个服务定义的 WSDL。 信息:无法解析 WSDL。 信息:使用 http://localhost:8080/WebSercviceOne/WebSercviceOne?WSDL 调用 wsimport 严重:wsimport 失败 信息: Metro 监控 rootname 成功设置为:amx:pp=/mon/server-mon[server],type=WSEndpoint,name=WebServiceOne-WebServiceOnePort 警告:容器 org.glassfish.webservices.JAXWSContainer@7339ea2c 不支持类 com.sun.xml.ws.api.server.Module 信息:WS00019:已部署 EJB 端点 ServiceOne 监听地址http://ericman-PC:8080/WebSercviceOne/WebSercviceOne 信息:WEB0671:在 [/ServiceOne] 加载应用程序 [ServiceOne] INFO:ServiceOne 在 511 毫秒内成功部署。 信息:解析 WSDL...
【问题讨论】:
-
WebServices 可以肯定地访问数据库,我自己做的。我们需要有关异常的更多详细信息。也许堆栈跟踪可以提供帮助?我真的怀疑这就是失败的原因。
-
Error generating artifacts for the following WSDL http://localhost:8080/CalculatorWS/CalculatorWS?WSDL Possible causes can be invoking https when the application is not configured for security这是我尝试测试 Web 服务时告诉我的内容 -
注意:你应该注入 DataSource/EntityManager。不要调用 DriverManager.getConnection。
-
注意:遵守 Java 命名约定:方法名以小写开头。
-
"但是当在 Web 服务中 NetBeans 不允许我部署项目时,它说它无法创建 WSDL。"你能进一步解释一下吗?您如何部署 WebService?
标签: java mysql web-services netbeans