[英]Spring SQL Proper way to use JdbcTemplate.update()
I am following a tutorial found here . 我正在跟踪此处找到的教程。 And am trying to follow it with an independent project I am working on called the Ticketing System.
并且正在尝试跟我正在从事的独立项目“票务系统”保持一致。 So i created this method:
所以我创建了这个方法:
public void create(Integer ticketNumber, Date timeOpened, String priorityLevel, String caseOwner) {
String sql = "insert into user_ticket (ticket_number, opened, priority, case_owner) values (?, ?, ?, ?)";
jdbcTemplateObject.update(sql, ticketNumber, timeOpened, priorityLevel, caseOwner);
System.out.println("Created Record Ticket Number = " + ticketNumber + " Time Opened = " + timeOpened + "Priority Level " +
priorityLevel + " Case Owner: " + caseOwner);
return;
}
But the problem is that when I try to use this line: 但是问题是当我尝试使用此行时:
jdbcTemplateObject.update(sql, ticketNumber, timeOpened, priorityLevel, caseOwner);
I get an error: 我收到一个错误:
The method update(String, Object[], int[]) in the type JdbcTemplate is not applicable for the arguments (String, Integer, Date, String, String)
I understand that the arguments I have provided may not be the right to use the update() method and I am still learning SpringJDBC. 我知道我提供的参数可能不是使用update()方法的权利,并且我仍在学习SpringJDBC。 Can someone tell me if there is an alternative way of using this method that can satisfy all the arguments I am providing?
有人可以告诉我是否有其他方法可以满足我所提供的所有论点?
Instead of passing the the variables in update()
you should put everything in Object[]
and then pass it. 而不是将变量传递给
update()
您应将所有内容都放入Object[]
,然后将其传递。
Here is the code snippet: 这是代码片段:
public void create(Integer ticketNumber, Date timeOpened, String priorityLevel,
String caseOwner) {
String sql = "insert into user_ticket (ticket_number, opened, priority, case_owner)
values (?, ?, ?, ?)";
Object[] params = {ticketNumber, timeOpened, priorityLevel, caseOwner};
jdbcTemplateObject.update(sql, params);
System.out.println("Created Record Ticket Number = " + ticketNumber +
" Time Opened = " + timeOpened + "Priority Level " +
priorityLevel + " Case Owner: " + caseOwner);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.