【发布时间】:2015-05-30 15:42:18
【问题描述】:
这里是视图:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<title>Books </title>
</h:head>
<h:body>
<h:link value="Add Books" outcome="addBook.xhtml"></h:link>
<table border="1">
<tr>
<td><b>ID</b> </td>
<td><b>Title</b> </td>
<td><b>Year</b> </td>
<td><b>ISBN</b> </td>
<td><b>Total</b> </td>
<td><b>Remaining</b></td>
</tr>
<ui:repeat value="#{booksController.fetch_book_data}" var="r">
<tr>
<h:form>
<td><h:inputText value="#{r.id}"></h:inputText></td>
<td><h:inputText value="#{r.title}"></h:inputText> </td>
<td><h:inputText value="#{r.year}"></h:inputText> </td>
<td><h:inputText value="#{r.isbn}"></h:inputText> </td>
<td><h:inputText value="#{r.total}"></h:inputText> </td>
<td><h:inputText value="#{r.remaining}"></h:inputText></td>
<td><h:commandButton value="update record" action="#{book.setUpdateBook_data()}"/></td>
</h:form>
</tr>
</ui:repeat>
</table>
</h:body>
</html>
View 将数据提交给setUpdateBook_data() 这是它的定义:
public String setUpdateBook_data() throws SQLException {
this.setRemaining(this.getTotal());
Statement stmt = con.createStatement();
String query = "UPDATE books SET title=? , year123=? , isbn=? , total=? , remaining=? where id=?";
PreparedStatement preparedStatement = con.prepareStatement(query);
preparedStatement.setString(1, this.getTitle());
preparedStatement.setString(2, this.getYear());
preparedStatement.setString(3, this.getIsbn());
preparedStatement.setInt(4, this.getTotal());
preparedStatement.setInt(5, this.getRemaining());
preparedStatement.setInt(6, this.getId());
preparedStatement.executeUpdate();
preparedStatement.close();
stmt.close();
return "success";
}
提交数据时,应用程序没有显示错误,但没有更新记录。我错过了什么?
我已经直接从 Netbeans 测试了以下查询,它在那里工作,但在这里不工作。
UPDATE books SET title='qqq' , year123='3009' , isbn='123456asdfgh' , total=10 , remaining=5 where id=5
【问题讨论】:
-
你的问题解决了吗?
标签: java sql jsf prepared-statement derby