This discussion is archived
1 Reply Latest reply: Dec 17, 2012 12:59 AM by gimbal2 RSS

jsf updating a null value in the database

980129 Newbie
Currently Being Moderated
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

<h:body>


<h:form id="formdel">

<h:column>
<f:facet name="header">
Emp Id
</f:facet>

<h:inputText value="#{data.empId}" />
</h:column>

<h:column>
<f:facet name="header">
Emp Name
</f:facet>

<h:inputText value="#{data.empName}" />
</h:column>

<h:column>
<f:facet name="header">
Emp Department
</f:facet>
<h:inputText value="#{data.empDepartment}" />

</h:column>

<h:column>
<h:commandButton value="Update" action="#{updatebean.upd(data.empId)}" />
</h:column>

</h:dataTable>
</h:form>
</h:body>
@ManagedBean(name="updatebean")
@RequestScoped
public class Updatebean {

        private long empID;
        private String empname;
        private String empdepartment;


        public long getEmpID() {
        return empID;
        }
        public void setEmpID(long empID) {
        this.empID = empID;
        }
        public String getEmpName() {
        return empname;
        }
        public void setEmpName(String empname) {
        this.empname = empname;
        }
        public String getEmpDepartment() {
        return empdepartment;
        }
        public void setEmpDepartment(String empdepartment) {
        this.empdepartment = empdepartment;
        }



public String upd(long empID)
{

int k = 0;


try
{

connections goes here -----------



String sql = "UPDATE employee SET empname='"+empname+"',empdepartment='"+empdepartment+"' where empid='"+empID+"'";

ps= con.prepareStatement(sql);

k = ps.executeUpdate();
System.out.println("RecorD updated Successfully");
}
catch(Exception e)
{
System.out.println(e);
}
  • 1. Re: jsf updating a null value in the database
    gimbal2 Guru
    Currently Being Moderated
    1. use \
     tags
    2. Don't post fake code, post the real code
    3. just what do you mean by 'null values were updated'? You mean null values are inserted into the database?                                                                                                                                                                                                                                                                                                                                                            

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points