0

Here is my java code to update database table and editing cell from UI.

From UI for caption column to edit its fine but its not updating column values in database table.

public void onCellEdit(CellEditEvent event) {
    System.out.println("inside cell edit");

     UIColumn col=(UIColumn) event.getColumn();
    DataTable o = (DataTable) event.getSource();
    Object oldValue = event.getOldValue();
    Object newValue = event.getNewValue();
    LabelsVO info = (LabelsVO) o.getRowData();
    int newModel = info.getLang_no();
    int newData=info.getLabel_no();

    System.out.println("row index in event method " + event.getRowIndex());
    System.out.println("old value" + oldValue);
    System.out.println("new value" + newValue);
    System.out.println("column1 :" + col.getHeader());

    try {
        conn=Database.getConnection();
        stmt = conn.prepareStatement("update ias_labels set caption_det =? where lang_no =? and label_no=?");
        stmt.setInt(1, newModel);
        stmt.setInt(2, newData);
        stmt.setString(3, newValue.toString());
        int rset = stmt.executeUpdate();
        conn.commit();
        if (rset != 0) {
            System.out.println("updated!!!");
        } else {
            System.out.println("not updated!!!");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    if (newValue != null && !newValue.equals(oldValue)) {
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

here is my front end class

<p:layoutUnit position="center" resizable="true" closable="true" collapsible="true">
                    <p:dataTable id="dataTable" var="lab" value="#{labelsMB.userLogList}" editable="true" editMode="cell"  
                                 paginator="true" rows="10"  
                                 paginatorTemplate="  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="5,10,15">  
                        <f:facet name="header">  
                            Labels Details
                        </f:facet>
                        <p:ajax event="cellEdit" immediate="true" listener="#{labelsMB.onCellEdit}" update="dataTable" />

                        <p:column headerText="Caption" sortBy="#{lab.caption_det}" filterBy="#{lab.caption_det}" width="40">  
                            <p:cellEditor>
                                <f:facet name="output">
                                    <h:outputText value="#{lab.caption_det}"/>
                                </f:facet>
                                <f:facet name="input">
                                    <h:inputText value="#{lab.caption_det}" style="width:96%"/>
                                </f:facet>
                            </p:cellEditor>
                            </p:column>

                        <p:column sortBy="#{lab.label_no}" filterBy="#{lab.label_no}" width="10">  
                            <f:facet name="header">  
                                <h:outputText value="Label No" />  
                            </f:facet>  
                            <h:outputText value="#{lab.label_no}" />  
                        </p:column>  
                        <p:column sortBy="#{lab.lang_no}" filterBy="#{lab.lang_no}" width="10">  
                            <f:facet name="header">  
                                <h:outputText value="Langauge No" />  
                            </f:facet>  
                            <h:outputText value="#{lab.lang_no}" /> 
                        </p:column> 
                        <p:column sortBy="#{lab.lang_name}" filterBy="#{lab.lang_name}" width="10">  
                            <f:facet name="header">  
                                <h:outputText value="Langauge Name" />  
                            </f:facet>  
                            <h:outputText value="#{lab.lang_name}" /> 
                        </p:column> 
                        <f:facet name="footer">
                            <p:commandButton id="dataTable" icon="ui-icon-disk" iconPos="left" ajax="false" value="Save" action="#{labelsMB.onCellEdit(event)}" />
                        </f:facet>
                    </p:dataTable>  
halfer
  • 19,824
  • 17
  • 99
  • 186
huq
  • 11
  • 3
  • If there is an exception then please show us the stacktrace. Are you sure, that your SQL insert code is executed (stepping with debugger)? What is the return value of `executeUpdate()`? Are you sure, there are records present fulfilling the where clause of your SQL statement? If you execute the very same SQL statement (including actual parameter values) with a SQL console, is there the expected effect? – vanje Mar 15 '16 at 12:26
  • am getting same value as what i have in databse value after executing and debugging.....even am getting error is coloumn index is invalid number here executeUpdate() ...i dont no what is this.. – huq Mar 15 '16 at 12:31
  • If you got an error, please show us the full stack trace! Otherwise it is impossible to help you. – vanje Mar 15 '16 at 12:39
  • ultimate inside cell edit inside cell edit row index in event method 3 old valuenewValue new valuenewValue column1 :null java.sql.SQLSyntaxErrorException: ORA-01722: invalid number – huq Mar 15 '16 at 12:47
  • Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) ... 33 more Caused by: java.lang.NullPointerException at com.ultimate.managedBeans.LabelsMB.onCellEdit(LabelsMB.java:99) – huq Mar 15 '16 at 12:48
  • 15-Mar-2016 18:16:58.326 WARNING [http-nio-9999-exec-12] com.sun.faces.lifecycle.InvokeApplicationPhase.execute #{labelsMB.onCellEdit(event)}: java.lang.NullPointerException javax.faces.FacesException: #{labelsMB.onCellEdit(event)}: java.lang.NullPointerException – huq Mar 15 '16 at 12:49
  • java.lang.NullPointerException - Stack Trace javax.faces.el.EvaluationException: java.lang.NullPointerException at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) at javax.faces.component.UICommand.broadcast(UICommand.java:315) – huq Mar 15 '16 at 12:53
  • So the database error is ["ORA-01722: invalid number"](http://www.orafaq.com/wiki/ORA-01722#When_doing_an_INSERT_INTO_..._VALUES_.28....29). It seems you tried to insert a string for a number column. What is the datatype of column `label_no`? – vanje Mar 15 '16 at 13:28
  • datatype of column label_no is NUMBER – huq Mar 16 '16 at 03:55
  • datatype of column lang_no is NUMBER .....datatype of column caption_det is VARCHAR – huq Mar 16 '16 at 03:59

0 Answers0