jdbc - How to edit database table in JSF -
i'm having bean class id,firstname,lastname attributes having public getters , setters, , updateemployee method.
i'm using following jsf page database table values.
when click on update button success page shown values not changing in database. can 1 tell me reason why vales not getting change in database?
thanks in advance.
jsf page:
<h:datatable value="#{tablebean.employeelist}" var="employee" border="1"> <h:column> <f:facet name="header">first name</f:facet> <h:inputtext value="#{employee.firstname}" /> </h:column> <h:column> <f:facet name="header">last name</f:facet> <h:inputtext value="#{employee.lastname}" /> </h:column> </h:datatable> <h:commandbutton value = "update" action="#{employee.updateemployee}"/>
employee.java:
public string updateemployee(){ string query = "update employee set firstname = ?,lastname = ? 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; } { try{ if (!committed) conn.rollback(); pstmt.close(); conn.close(); }catch(exception e){ e.printstacktrace(); } }
your values automatically bound if have corresponding properties in backing bean.
you have submit data in order bean values updated. add commandbutton or commandlink in form this:
<h:form> <h:datatable> ... </h:datatable> <h:commandbutton value="submit" action="tablebean.actionmethod"> </h:form>
Comments
Post a Comment