Dec 20, 2016, 9:37 AM
1 Posts

Error while inserting JDBCRecord to SQL Table

  • Category: Extension Library
  • Platform: All
  • Release: 8.5.3
  • Role: Developer
  • Tags: XPages Application
  • Replies: 0

The acceptChanges() method throws SyncProviderException while trying to insert a new record and the error message is "1 conflicts while synchronizing". The error occurs only when there is a column in the SQL table that increments it's value by itself (there could be other scenarios too that I haven't encountered yet). It would  have been helpful if a more detailed error was thrown.

Anybody knows of a way to get a more detailed error message or a way to fix this? Also, is there a way to get a return value after the insert using this method? I would have asked Philip Riand directly but I don't have his contact details.

Here is the complete code (Except the connection manager control, that is in another custom control).

 

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
    <xp:panel id="boxCase">
        <xp:this.data>
            <xe:objectData var="docKeyword"
                createObject="#{javascript:new app.documents.Keyword()}">
            </xe:objectData>
            <xe:jdbcRowSet var="jdbcRowSet1" maxRows="1"
                connectionManager="jdbcConnectionManager1"
                sqlQuery="select * from dbo.Table_Test where 1=4">
            </xe:jdbcRowSet>                
            <xe:objectData var="recKeyword">
                <xe:this.createObject><![CDATA[#{javascript:
                if (jdbcRowSet1.getCount()>0) {
                    jdbcRowSet1.getRow(0);
                } else {
                    jdbcRowSet1.newRow(0);
                }
            }]]></xe:this.createObject>
            </xe:objectData>
        </xp:this.data>

        <xp:inputText id="inputText14" value="#{recKeyword.Country}">
        </xp:inputText>
        
        <xp:button type="button" themeId="Button.Green.Small" id="button1">
            Save
            <xp:eventHandler event="onclick" submit="true"
                refreshMode="partial" refreshId="boxCase">
                <xp:this.action><![CDATA[#{javascript:
                recKeyword.setValue("ID",1); //AUTO INCRMENTED COLUMN
                jdbcRowSet1.saveRow(recKeyword);
                try {
                    jdbcRowSet1.acceptChanges();
                } catch(e) {
                    print(e.getMessage());
                }
                }]]></xp:this.action>
            </xp:eventHandler>
        </xp:button>
    </xp:panel>
</xp:view>