Here is the view:
<?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
submits data to setUpdateBook_data()
here is its definition:
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";
}
When data is submitted application shows no error but record is not being updated. What did I miss?
I have tested following query directly from Netbeans, it works there but not here.
UPDATE books SET title='qqq' , year123='3009' , isbn='123456asdfgh' , total=10 , remaining=5 where id=5