由于某些原因,当我尝试创建Web服务以将id,name和idno插入mysql数据库时,下面的代码不会执行。我已添加MYSQL JDBC驱动程序 - MYSQL连接器库,但我得到此错误“严重:java.sql.SQLException:找不到适合jdbc的驱动程序:mysql:// localhost:3306/web”。 我已经通过一些人的答案,但似乎没有得到答案。可能是什么原因?任何人?java.sql.SQLException:找不到适合jdbc的驱动程序:mysql
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。 – bmm
你如何部署它?您应该可以在netbeans中运行它,但要在服务器上运行它,通常需要在服务器上安装*。 –