Mule advanced JDBC transport

Source: Internet
Author: User

The address of this article in my javaeyeblog is as follows:

Http://lcllcl987.javaeye.com/blog/350502

Synchronously update.

 

Continue traveling in the XML ocean of mule.
Send a map message to a VM: queue. The mule dynamically executes the SQL statement based on the map information and returns data. The SELECT query mule returns map data by default.
Configuration file:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <mule xmlns = "http://www.mulesource.org/schema/mule/core/2.1" <br/> xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" <br/> xmlns: JDBC = "http://www.mulesource.com/schema/mule/jdbc/2.1" <br/> xmlns: spring = "http://www.springframework.org/schema/beans" <br/> xmlns: Vm = "http://www.mulesource.org/schema/mule/vm/2.1" <br/> xsi: schemalocation = "<br/> http://www.mulesource.com/schema/mule/jdbc/2.1 H Ttp: // www.mulesource.com/schema/mule/jdbc/2.1/mule-jdbc-ee.xsd <br/> http://www.mulesource.org/schema/mule/core/2.1 http://www.mulesource.org/schema/mule/core/2.1/mule.xsd http://www.springframework.org/schema/beans <br/> http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.mulesource.org/schema/mule/vm/2.1 http://www.mulesource.org/schema/mule/vm/2.1/mule-vm.xsd <br/> <br /> <Spring: bean id = "datasource" <br/> class = "org. apache. commons. DBCP. basicdatasource "<br/> destroy-method =" close "> <br/> <spring: property name =" driverclassname "<br/> value =" com. mySQL. JDBC. driver "/> <br/> <spring: property name =" url "<br/> value =" JDBC: mysql: // 192.168.10.120/sand_res "/> <br/> <spring: property name =" username "value =" username "/> <br/> <spring: property name = "password" value = "888 "/> <Br/> <spring: property name = "maxactive" value = "30"/> <br/> <spring: property name = "maxidle" value = "10"/> <br/> <spring: property name = "maxwait" value = "1000"/> <br/> <spring: property name = "defaultautocommit" value = "true"/> <br/> </spring: bean> <br/> <JDBC: connector name = "jdbcconnector" datasource-ref = "datasource"> <br/> <JDBC: Query key = "selectuser" <br/> value = "select first_name, last_name from App_user where first_name = # [Map-Payload: firstname] "/> <br/> <JDBC: query key = "insertuser" <br/> value = "insert into app_user <br/> (ID, first_name, last_name) values (# [Map-Payload: Id], # [Map-Payload: firstname], # [Map-Payload: lastname]) "/> <br/> </jdbc: Connector> </P> <p> <! -- <Br/> the mule model initialises and manages your UMO components <br/> --> <br/> <model name = "databasemodel"> <br/> <service name = "insertumo"> <br/> <! -- Any number of endpoints can be added to an inbound router --> <br/> <inbound> <br/> <VM: inbound-endpoint Path = "query"/> <br/> </inbound> <br/> <! -- <Br/> an outbound router can have one or more router deployments that can be <br/> invoked depending on business rules, message contents, headers or any other <br/> criteria. the pass-through-router is a router that automatically passes <br/> on every message it has es <br/> --> <br/> <outbound> <br/> <pass -through-router> <br/> <JDBC: outbound-endpoint querykey = "selectuser" synchronous = "true"/> <br/> </pass-through-router> <br/> </outbound> <br/> </service> <br/> </model> <br/> </mule>

NOTE: If mule uses 2.1, the namespase Suffix of JDBC transport is com, instead of org. If an error is written, the IDE will not prompt, and the program exception is also very strange. I had to wait for an afternoon :(
Test procedure:
Public class mymuleclienttest <br/>{< br/> Public static void main (string [] ARGs) throws muleexception <br/>{< br/> // create mule <br/> mulecontext; <br/> string Config = "my-mule-jdbc-config.xml "; <br/> mulecontext = new defaultmulecontextfactory (). createmulecontext (config); <br/> mulecontext. start (); <br/> // creat mule client <br/> muleclient client = new muleclient (); <br/> map = new hashmap (); <br/> map. put ("firstname", "Feng"); <br/> mulemessage response = client. send ("VM: // query", MAP, null); <br/> system. out. println ("response =" + response. getpayload (); <br/>}< br/>}
The executed SQL is:
Select first_name, last_name from app_user where first_name = "Feng"

Insert execution is similar. You only need to modify it as follows:
<Outbound> <br/> <pass-through-router> <br/> <JDBC: outbound-endpoint querykey = "insertuser" synchronous = "true"/> <br/> </pass-through-router> <br/> </outbound>

It seems that the JDBC transtort of mule is the ibatis of the crying version,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.