【发布时间】:2016-11-28 06:53:11
【问题描述】:
由于某些原因,当我尝试创建 Web 服务以将 id、name 和 idno 插入 mysql 数据库时,以下代码不会执行。我添加了 MYSQL JDBC 驱动程序 - MYSQL 连接器库,但我收到此错误“严重:java.sql.SQLException:找不到适合 jdbc:mysql://localhost:3306/web 的驱动程序”。 我经历了一些人的回答,但似乎没有得到答案。可能是什么原因?有人吗?
package com.database.www;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
@WebService(serviceName = "database")
public class database {
@WebMethod(operationName = "hello")
public void hello(@WebParam() int id, String name, String idno ) {
try (
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/web", "root", "");
Statement stm = conn.createStatement();) {
String insert = "INSERT INTO `web` " + "VALUES ("+id+", '"+name+"','"+idno+"' )";
int exc = stm.executeUpdate(insert);
System.out.println("The SQL Command is: " + insert);
System.out.println("Inserted Successfullly!");
}
catch (SQLException e){
e.printStackTrace();
}
}
}
【问题讨论】:
-
如何你添加了 mysql 连接器?你是如何部署它的?
-
在库中,添加库,然后我在 netbeans IDE 上选择了 JDBC Lib。
-
你是如何部署它的?您应该能够在 netbeans 中运行它,但要在您的服务器上运行它,通常需要在服务器上安装。
-
我到底应该安装什么?我只是在清理和构建后单击部署。
标签: java mysql web-services jdbc