sqlUpdate Insert Error

  • nzblue_fish
  • 09/30/09
  • Offline
Posted: Tue, 05/04/2010 - 01:09

Hi mashers,

I'm trying to use SQL commands to load a database with data, but I'm getting an error message when the emml executes. I know the code works because I've tested it with much simpler example of data and values. Now I'm working toward my intended use, but have run in to this error.

Does anyone have any suggestions on where the problem might be.

Cheers, Innes

640 ERROR [com.jackbe.jbp.jems.moe.runtime.JEMSDesignerImpl] -
<Error execution Mashup Script : org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [INSERT into client(clinicgrp,clientno,lastname,firstname,title,address1,address2,address3,postcode)         VALUES(?,?,?,?,?,?,?,?,?)]; Unable to convert between net.sf.saxon.dom.DOMNodeList and JAVA_OBJECT.; nested exception is java.sql.SQLException: Unable to convert between net.sf.saxon.dom.DOMNodeList and JAVA_OBJECT. : EMML Line # 106 : EMML Line # : 6>

Here's the full emml code:

        <variables>
            <variable name="global.AHCDataStore.SQL.jdbcURL" type="string" />
            <variable name="global.AHCIntranet.SQL.jdbcDriver" type="string" />
            <variable name="global.jdbcUserID" type="string" />
            <variable name="global.jdbcPassword" type="string" />
            <variable name="sqlCmdResult" type="document" />
            <variable name="sqlRecord" type="document" />
            <variable name="clinicgrp" type="string" />
            <variable name="clientno" type="number" />
            <variable name="lastname" type="string" />
            <variable name="firstname" type="string" />
            <variable name="title" type="string" />
            <variable name="address1" type="string" />
            <variable name="address2" type="string" />
            <variable name="address2" type="string" />
            <variable name="postcode" type="string" />
    <variable name="ahcRecordSet" type="document">
        <records>
            <record>
                <clientno>23871</clientno>
                <lastname>Leech</lastname>
                <firstname>Daphine</firstname>
                <title />
                <address1>248 State Highway 27</address1>
                <address2>RD 1 </address2>
                <address3>Tirau</address3>
                <postcode>3484</postcode>
                <preferredvet />
                <areacode />
                <clienttype />
                <code />
                <salesrep />
            </record>
            <record>
                <clientno>23872</clientno>
                <lastname>Macfarlane</lastname>
                <firstname>Philip</firstname>
                <title>Mr</title>
                <address1>341 Tauwhare Road</address1>
                <address2>RD3</address2>
                <address3>Hamilton</address3>
                <postcode>3285</postcode>
                <preferredvet />
                <areacode />
                <clienttype />
                <code />
                <salesrep />
            </record>
            <record>
                <clientno>23873</clientno>
                <lastname>Blogs</lastname>
                <firstname>Jo</firstname>
                <title>Mr</title>
                <address1>Vfansdjgnank</address1>
                <address2 />
                <address3 />
                <postcode />
                <preferredvet />
                <areacode />
                <clienttype />
                <code />
                <salesrep />
            </record>
        </records>
    </variable>                   
        </variables>

        <datasource name="ahcDataStore" url="{$global.AHCDataStore.SQL.jdbcURL}"
            driverClassName="{$global.AHCIntranet.SQL.jdbcDriver}" username="{$global.jdbcUserID}"
            password="{$global.jdbcPassword}" />

        <sqlBeginTransaction name="ahcDataStore" />

        <sqlUpdate name="ahcDataStore"
            statement="CREATE TABLE client (clinicGrp varchar(5) NOT NULL,
                                            clientNo int NOT NULL,
                                            lastname varchar(40),
                                            firstname varchar(30),
                                            title varchar(15),
                                            address1 varchar(50),
                                            address2 varchar(30),
                                            address3 varchar(30),
                                            postcode varchar(10),
                                            CONSTRAINT pk_clnGrpClient PRIMARY KEY (clinicgrp,clientno)
                                            )"
            outputvariable="sqlCmdResult" />
        <display message="sqlCmdResult=" variable="sqlCmdResult" />

        <foreach items="$ahcRecordSet/*:records/*:record" variable="sqlRecord">

            <display message="&#10;&#13;record=" variable="sqlRecord" />
            <assign literal="ahc" outputvariable="clinicgrp" />
            <assign fromexpr="$sqlRecord/*:clientno/text()" outputvariable="clientno" />
            <assign fromexpr="$sqlRecord/*:lastname/text()" outputvariable="lastname" />
            <assign fromexpr="$sqlRecord/*:firstname/text()" outputvariable="firstname" />
            <assign fromexpr="$sqlRecord/*:title/text()" outputvariable="title" />
            <assign fromexpr="$sqlRecord/*:address1/text()" outputvariable="address1" />
            <assign fromexpr="$sqlRecord/*:address2/text()" outputvariable="address2" />
            <assign fromexpr="$sqlRecord/*:address3/text()" outputvariable="address3" />
            <assign fromexpr="$sqlRecord/*:postcode/text()" outputvariable="postcode" />
           
            <sqlUpdate name="ahcDataStore"
                statement="INSERT into client(clinicgrp,clientno,lastname,firstname,title,address1,address2,address3,postcode)
                            VALUES(:clinicgrp,:clientno,:lastname,:firstname,:title,:address1,:address2,:address3,:postcode)"
                outputvariable="sqlCmdResult" />
            <display message="sqlCmdResult=" variable="sqlCmdResult" />
        </foreach>

        <sqlCommit name="ahcDataStore" />
cfff4
0
Your rating: None

Hi everyone, Problem found

  • nzblue_fish
  • 09/30/09
  • Offline
  • Tue, 05/04/2010 - 18:40

Hi everyone,

Problem found and solved, but still a bit of a curiosity. The problem was being caused by the <address3 /> nodes from the constructed test variable <ahcRecordSet> above. I have no idea why. I created this test variable from a document fragment cut+pasted from the Studio console window (saved typing) so I thought perhaps I had picked up some non-displaying characters when I did. Interestingly, even when I deleted and hand typed the nodes, I still got the same error message.

Solution: run the content of the node through normalize-space() during the variable assignment. So, while:

<assign fromexpr="$sqlRecord/*:address3/text()" outputvariable="address3" />

caused the error message I was getting above, the following stopped it:

<assign fromexpr="normalize-space($sqlRecord/*:address3/text())" outputvariable="address3" />

Go figure!

So I'm now normalize-space'ing during each assignment just to make sure this doesn't happen while processing any other nodes.

Anyone out there prepared to hazard a guess as to the reason for this curiosity?

Cheers, Innes

 


 Hi Innes,   The problem

  • raj
  • 09/22/08
  • Offline
  • Wed, 05/05/2010 - 14:19

 Hi Innes,

 

The problem seems to originate because of variable declaration typo in following snippet.

<variable name="address1" type="string" />

<variable name="address2" type="string" />

<variable name="address2" type="string" />

Notice that address3 is not declared as "string" type (due to typo).

Now an assignment is being made to a non-declared variable of unknown type. This causes an implicit variable creation , whose type inherits from source expressions type (which is a NodeList in this case).

<assign fromexpr="$sqlRecord/*:address3/text()" outputvariable="address3" />

If address3 was declared as string, the above assignment would have done appropriate type conversion.

Since, address3 is a NodeList, the final result fails with 

"Unable to convert between net.sf.saxon.dom.DOMNodeList and JAVA_OBJECT."

So, the  fix would be correct the typo by declaring address3 explicitly as string type.

At our end, we will investigate on how we can handle this better by either reporting a more appropriate error msg OR do better type-conversion when involving NodeList.

hth

raj.  chief masher @ jackbe


Hi Raj, many thanks for the

  • nzblue_fish
  • 09/30/09
  • Offline
  • Wed, 05/05/2010 - 22:44

Hi Raj,

many thanks for the reply. Sorry about that ... should have put my glasses on! :)

It seems so obvious now that you point it out and I should have picked that up myself. With the typo corrected it works perfectly.

Lesson learnt here ... check your code more carefully! 

Interestingly, as you explained, there are times when variables are created without you having to explicitly declare them and that's something to watch out for. My typo would have been more obvious if the reference to "address3" had failed because it was not declared.

Cheers, Innes


We all need better glasses

  • smitchell
  • 08/29/08
  • Offline
  • Thu, 05/06/2010 - 12:55

We all need better glasses from time to time .

And I know I keep harping, but the fact that variables are created implicitly is in the docs. Any variable you have in @outputvariable on any statement can create a variable if the name doesn't match one explicitly declared.

<!--Session data-->

 

<!--Session data-->

 

<!--Session data-->

 

Sara, technical writer/jackbe