Question

I have a problem with the DBreport mediator which output a syntax error, but I can't see any error in the SQL statement

<sequence xmlns="http://ws.apache.org/ns/synapse" name="_dbcount">
   <dblookup>
      <connection>
         <pool>
            <password>1234</password>
            <user>root</user>
            <url>jdbc:mysql://localhost:3306/new_db</url>
            <driver>com.mysql.jdbc.Driver</driver>
         </pool>
      </connection>
      <statement>
         <sql>
            <![CDATA[            select * from consume where username= ? and id_api+ ?]]></sql>
            <parameter value="riccardo" type="VARCHAR" />
            <parameter value="1" type="INTEGER" />
            <result name="result_use" column="use" />
            <result name="result_user" column="username" />
         </statement>
      </dblookup>
      <dbreport>
         <connection>
            <pool>
               <password>1234</password>
               <user>root</user>
               <url>jdbc:mysql://localhost:3306/new_db</url>
               <driver>com.mysql.jdbc.Driver</driver>
               <property name="autocommit" value="false" />
            </pool>
         </connection>
         <statement>
            <sql>
               <![CDATA[UPDATE consume SET use=21 WHERE username='riccardo' AND id_api='1']]></sql>
            </statement>
         </dbreport>
         <log level="custom">
            <property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="result for client" expression="get-property('result_user')" />
            <property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="result for use" expression="get-property('result_use')" />
         </log>
      </sequence>

The first DB lookup works fine but the second SQL statement in the DBreport cannot update the value:

ERROR - DBReportMediator Error execuring insert statem
ent : UPDATE consume SET use='21' WHERE username='riccardo' AND id_api='1' again
st DataSource : jdbc:mysql://localhost:3306/new_db
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near 'use='21' WHERE username='riccardo' AND id_api=
'1'' at line 1
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)...

My tables are as follows:

consume (int id, varchar username, int id_api, int use) users (int id, varchar username, varchar password)

many thanks

EDIT I think there are major issues with DBREPORT AND DBLOOKUP mediators when writing on a Mysql DB, reading is fine, but Update and Insert just don't work... tell me if I am wrong

Was it helpful?

Solution

Nuvio,

I think this issue arises not because of something wrong in the DBReport mediator. While going through the reported stack trace and the sequence configuration I can see you have defined "use" as a column name. I'm not quite sure how you created a database column with the term "use" because it is a MySQL keyword and MySQL query compiler should throw a SQLException whenever you have a keyword as a column or any other user defined attribute in your SQL query. Having a non-keyword name for in place of the column "use" would fix your problem.

Cheers, Prabath

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top