By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,805 Members | 1,392 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,805 IT Pros & Developers. It's quick & easy.

jsf updating a null value in the database

P: 26
i tried to update the database but null values were updated. I think the problem
is from the form inputs

below is the form fields and the bean class

Expand|Select|Wrap|Line Numbers
  1. <h:body>
  2.  
  3.  
  4. <h:form id="formdel">
  5.  
  6. <h:column>
  7. <f:facet name="header">
  8. Emp Id
  9. </f:facet>
  10.  
  11. <h:inputText value="#{data.empId}" />
  12. </h:column>
  13.  
  14. <h:column>
  15. <f:facet name="header">
  16. Emp Name
  17. </f:facet>
  18.  
  19. <h:inputText value="#{data.empName}" />
  20. </h:column>
  21.  
  22. <h:column>
  23. <f:facet name="header">
  24. Emp Department
  25. </f:facet>
  26. <h:inputText value="#{data.empDepartment}" />
  27.  
  28. </h:column>
  29.  
  30. <h:column>
  31. <h:commandButton value="Update" action="#{updatebean.upd(data.empId)}" />
  32. </h:column>
  33.  
  34. </h:dataTable>
  35. </h:form>
  36. </h:body>
  37.  
  38.  
  39.  

Expand|Select|Wrap|Line Numbers
  1. @ManagedBean(name="updatebean")
  2. @RequestScoped
  3. public class Updatebean {
  4.  
  5.         private long empID;
  6.         private String empname;
  7.         private String empdepartment;
  8.  
  9.  
  10.         public long getEmpID() {
  11.         return empID;
  12.         }
  13.         public void setEmpID(long empID) {
  14.         this.empID = empID;
  15.         }
  16.         public String getEmpName() {
  17.         return empname;
  18.         }
  19.         public void setEmpName(String empname) {
  20.         this.empname = empname;
  21.         }
  22.         public String getEmpDepartment() {
  23.         return empdepartment;
  24.         }
  25.         public void setEmpDepartment(String empdepartment) {
  26.         this.empdepartment = empdepartment;
  27.         }
  28.  
  29.  
  30.  
  31. public String upd(long empID)
  32. {
  33.  
  34. int k = 0;
  35.  
  36.  
  37. try
  38. {
  39.  
  40. connections goes here -----------
  41.  
  42.  
  43.  
  44. String sql = "UPDATE employee SET empname='"+empname+"',empdepartment='"+empdepartment+"' where empid='"+empID+"'";
  45.  
  46. ps= con.prepareStatement(sql);
  47.  
  48. k = ps.executeUpdate();
  49. System.out.println("RecorD updated Successfully");
  50. }
  51. catch(Exception e)
  52. {
  53. System.out.println(e);
  54. }
  55.  
  56.  
Dec 16 '12 #1
Share this Question
Share on Google+
1 Reply


Rangan
P: 8
You didnt write <h:datatable> opening tag.

inside the tag assign value attribute list of bean or single bean.

<h:datatable value="#{updatebean.updateBeanList}" var="data">
OR

<h:datatable value="#{updatebean}" var="data">

this code will help you.
Dec 18 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.