所以我有一个更新方法来更新客户,它看起来像:
public static Customer UpdateCustomer(Customer customer){
System.out.println("Updating customer ");
try {
statement = connection.createStatement();
statement.executeUpdate("UPDATE customer " + "SET id = " + customer.getCustomerId() + "SET name = " + customer.getName() + "SET tagNo = " + customer.getTagNo() +
"SET telephoneNo = " + customer.getTelephoneNo() + "SET email = " + customer.getEmail() + "SET noOfTimesRecycles = " +
customer.getNoOfTimesRecycled());
} catch (SQLException ex) {
System.out.println("Error in updating customer");
ex.printStackTrace();
}
return customer;
}
我不确定如何进行测试。我到目前为止对测试的了解是:
public static Customer UpdateCustomer(Customer customer){
return UpdateCustomer(customer);
}
public static void main(String [] args)
{
connectTest();
UpdateCustomer(105,"John", 4179, "+4475855216");
closeTest();
}
好吧,它在UpdateCustpmer给了我错误,因为它期望Type客户。
任何人都可以帮我吗?谢谢
最佳答案
简单的测试方法如下。
公共静态客户UpdateCustomer(客户客户){
System.out.println(“更新客户”);
try {
statement = connection.createStatement();
String query = "UPDATE customer " + "SET id = " + customer.getCustomerId() + "SET name = " + customer.getName() + "SET tagNo = " + customer.getTagNo() +
"SET telephoneNo = " + customer.getTelephoneNo() + "SET email = " + customer.getEmail() + "SET noOfTimesRecycles = " +
customer.getNoOfTimesRecycled();
System.out.println("Update query is:::"+query);
statement.executeUpdate(query);
} catch (SQLException ex) {
System.out.println("Error in updating customer");
ex.printStackTrace();
}
return customer;
}
现在,复制“更新查询为”的日志并粘贴到数据库控制台(mysql或您正在使用的任何其他数据库)中。并检查其中的错误消息。