【发布时间】:2018-11-20 21:22:19
【问题描述】:
您好,我正在尝试测试连接到 mysql localhost (xampp) 的 Web 服务 Soap java,但我无法在数据库中插入任何行 这是我的代码
Conexion.java
import java.sql.Connection
import java.sql.DriverManager
public class Conexion {
public static final Connection ConectarMySQL() throws SQLException
{
Connection conn;
try
{
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/controldecalidad", "root", "");
}
catch(SQLException ex)
{
throw new SQLException(ex.getMessage());
}
return conn;
}
}
这里是网络服务
@WebMethod(operationName= "registra_rechazo")
public void registra_rechazo(@WebParam(name = "SKU")String SKU,@WebParam(name = "fecha")String fecha,
@WebParam(name = "num_captura")String num_captura,@WebParam(name = "pesoCaptura") int pesoCaptura)
{
try
{
Connection conn = Conexion.ConectarMySQL();
String sql = "INSERT INTO registra_rechazo VALUES(?,?,?,?)";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, SKU);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
pst.setString(2, dateFormat.format(fecha));
pst.setString(3, num_captura);
pst.setInt(4, pesoCaptura);
pst.execute();
pst.close();
conn.close();
}
catch(SQLException Ex)
{
}
}
这是错误 https://i.stack.imgur.com/aWO16.png
更新!!我检查了我的项目,我收到了这个新错误 https://i.stack.imgur.com/uHRQW.png
我错过了什么?请帮忙!!!!
【问题讨论】:
-
java.lang.reflect.InvocationTargetException 当您调用的方法尝试调用另一个引发异常的方法时抛出,所以我的建议是检查日志并尝试按照堆栈跟踪查看错误最初来自哪里
-
嗨!感谢您的反馈,您重新检查了 conexion 类,我在其他项目中尝试了它并且是正确的,没有错误,所以 de Connection 实例不是问题,然后我将准备好的语句更改为 stament,我有一个 java.lang.NullPointerException错误:/
-
在更新中,这是完整的错误信息吗?如果它没有发布整个错误,我相信它应该准确列出导致它的原因
标签: java mysql web-services soap netbeans-8