Sample 361: Introduction to DBReport Mediator

<definitions xmlns=""> <sequence name="main"> <in> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> </in> <out> <log level="custom"> <property name="text" value="** Reporting to the Database **"/> </log> <dbreport> <connection> <pool> <driver>org.apache.derby.jdbc.ClientDriver</driver> <url>jdbc:derby://localhost:1527/synapsedb;create=false</url> <user>synapse</user> <password>synapse</password> </pool> </connection> <statement> <sql>update company set price=? where name =?</sql> <parameter xmlns:m1="http://services.samples/xsd" xmlns:m0="http://services.samples" expression="//m0:return/m1:last/child::text()" type="DOUBLE"/> <parameter xmlns:m1="http://services.samples/xsd" xmlns:m0="http://services.samples" expression="//m0:return/m1:symbol/child::text()" type="VARCHAR"/> </statement> </dbreport> <send/> </out> </sequence> </definitions>


Sample 360 shows how to perform database lookups in Synapse. This sample illustrates how to write to a given database from Synapse using the dbreport mediator.


  • Setup a Derby database as described in the database setup guide
  • Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
  • Start Synapse using the configuration numbered 361 (repository/conf/sample/synapse_sample_361.xml)
    Unix/Linux: sh -sample 361
    Windows: synapse.bat -sample 361

Executing the Client

This sample demonstrates how to perform simple database write operations in Synapse. The dbreport mediator writes (i.e. inserts one row) to a table using the details available in messages. It works the same way as the dblookup mediator. In this sample, dbreport mediator is used for updating the stock price of the company using the last quote value which is calculated by evaluating an XPath against the response message. After running this sample, user can check the company table using the Derby client tool. It will show the value inserted by the dbreport mediator.

To try this out run the sample client as follows.

ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=IBM

Now execute the following SQL query against the Derby database using the Derby client tool.

select price from company where name='IBM';

This operation will return the stock quote value returned earlier by Axis2. You can compare the output of the sample Axis2 client with the output of the Derby client tool for confirmation.

Back to Catalog