Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to edit database table in JSF
    text
    copied!<p>I'm having a bean class with id,firstName,lastName attributes having public getters and setters, and an updateEmployee method. </p> <p>i'm using following jsf page to get database table values. </p> <p>When i click on update button success page is shown but values are not changing in the database. Can any one tell me the reason that why vales are not getting change in the database?</p> <p>Thanks in advance.</p> <p><strong>JSF page:</strong></p> <pre><code>&lt;h:dataTable value="#{tableBean.employeeList}" var="employee" border="1"&gt; &lt;h:column&gt; &lt;f:facet name="header"&gt;First name&lt;/f:facet&gt; &lt;h:inputText value="#{employee.firstName}" /&gt; &lt;/h:column&gt; &lt;h:column&gt; &lt;f:facet name="header"&gt;Last name&lt;/f:facet&gt; &lt;h:inputText value="#{employee.lastName}" /&gt; &lt;/h:column&gt; &lt;/h:dataTable&gt; &lt;h:commandButton value = "update" action="#{employee.updateEmployee}"/&gt; </code></pre> <p>Employee.java:</p> <pre><code>public String updateEmployee(){ String query = "update employee set firstName = ?,lastName = ? where id = 1"; pstmt = conn.prepareStatement(query); pstmt.setString(2,this.firstName); pstmt.setString(3,this.lastName); pstmt.executeUpdate(); // execute update statement conn.commit(); committed = true; return "success.xhtml"; }catch (Exception e) { e.printStackTrace(); return null; } finally { try{ if (!committed) conn.rollback(); pstmt.close(); conn.close(); }catch(Exception e){ e.printStackTrace(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload