JDBC Transport

beeline连接hive出错 Error: Could not open client transport with JDBC Uri 出现的错误:Error: Could not open client transport with JDBC Uri: jdbc:hive2://NODE01:10000: Failed to open new session: java.lang.RuntimeException:org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.se... 阅读详情

JDBC Transport

Introduction

The JDBC Transport allows you to send and receive messages with a database using the JDBC protocol. Common usage includes retrieving, inserting, updating, and deleting database records, as well as invoking stored procedures (e.g., to create new tables dynamically).

Some features are available only with the Mule Enterprise version of the JDBC transport, which is available with version 1.6 and later of Mule Enterprise. These enterprise-only features are noted below.

Features

The Mule Enterprise JDBC Transport provides key functionality, performance improvements, transformers, and examples not available in the Mule community release. The following table summarizes the feature differences.

FeatureSummaryMule CommunityMule Enterprise
Inbound SELECT QueriesRetrieve records using the SQL SELECT statement configured on inbound endpoints.xx
Large Dataset RetrievalEnables retrieval arbitrarily large datasets by consuming records in smaller batches. x
Acknowledgment StatementsSupports ACK SQL statements that update the source or other table after a record is read.xx
Basic Insert/Update/Delete StatementsIndividual SQL INSERT, UPDATE, and DELETE queries specified on outbound endpoints. One statement is executed at a time.xx
Batch Insert/Update/Delete StatementsSupport for JDBC batch INSERT, UPDATE, and DELETE statements, so that many statements can be executed together. x
Advanced JDBC-related TransformersXML and CSV transformers for easily converting to and from datasets in these common formats. x
Outbound SELECT QueriesRetrieve records using SQL SELECT statement configured on outbound endpoints. Supports synchronous queries with dynamic runtime parameters. x
Outbound Stored Procedure Support - BasicAbility to invoke stored procedures on outbound endpoints. Supports IN parameters but not OUT parameters.xx
Outbound Stored Procedure Support - AdvancedSame as Basic but includes both IN and OUT parameter support. OUT parameters can be simple data types or cursors x
Unnamed QueriesQueries that can be invoked programmatically from within service components or other Java code. This is the most flexible option, but also requires writing code.xx
Flexible Data Source ConfigurationSupport for configuration of data sources through JNDI, XAPool, or Spring.xx
TransactionsSupport for transactions via underlying Transaction Manager.xx

Important Note on Namespaces

When using Mule Enterprise JDBC features, note that you must import the EE namespace for the JDBC transport, and the XSD name is mule-jdbc-ee.xsd instead of mule-jdbc.xsd. For example, in Mule 2.1:

<mule 
    xmlns:jdbc="http://www.mulesource.com/schema/mule/jdbc/2.1"
    xsi:schemaLocation="http://www.mulesource.com/schema/mule/jdbc/2.1 http://www.mulesource.com/schema/mule/jdbc/2.1/mule-jdbc-ee.xsd">

As of Mule Enterprise 2.2, the path is slightly different (.org instead of .com, addition of /ee in path):

<mule 
    xmlns:jdbc="http://www.mulesource.org/schema/mule/ee/jdbc/2.2"
    xsi:schemaLocation="http://www.mulesource.org/schema/mule/ee/jdbc/2.2 http://www.mulesource.org/schema/mule/ee/jdbc/2.2/mule-jdbc-ee.xsd">

If you are not using Mule Enterprise JDBC features, you can use the Mule community release JDBC namespace:

<mule 
    xmlns:jdbc="http://www.mulesource.org/schema/mule/jdbc/2.2"
    xsi:schemaLocation="http://www.mulesource.org/schema/mule/jdbc/2.2 http://www.mulesource.org/schema/mule/jdbc/2.2/mule-jdbc.xsd">

Inbound SELECT Queries

Inbound SELECT queries are queries that are executed periodically (according to the pollingFrequency set on the connector).

Here is an example:

<spring:bean id="jdbcDataSource" class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
	<spring:property name="driverName" value="oracle.jdbc.driver.OracleDriver"/>
	<spring:property name="url" value="jdbc:oracle:thin:user/pass@host:1521:db"/>
</spring:bean>
...
<jdbc:connector name="jdbcConnector" pollingFrequency="10000" dataSource-ref="jdbcDataSource">
        <jdbc:query key="selectLoadedMules"
                    value="SELECT ID, MULE_NAME, RANCH, COLOR, WEIGHT, AGE from mule_source where ID between 0 and 20"/>
</jdbc:connector>
...
<model name="ExampleModel">
        <service name="InboundSelectExample">
            <inbound>
                <jdbc:inbound-endpoint queryKey="selectMules"/>
            </inbound>
            <outbound>
                <pass-through-router>
                    <vm:outbound-endpoint path="out"/>
                </pass-through-router>
            </outbound>
        </service>
</model>
...

In this example, the inboundSelectQuery would be invoked every 10 seconds (pollingFrequency=10000 ms). Each record from the result set is converted into a Map (consisting of column/value pairs), and this payload is sent to the VM endpoint shown above.

Inbound SELECT queries are limited because (1) generally, they cannot be called synchronously (unnamed queries are an exception), and (2) they do not support runtime parameters.

Large Dataset Retrieval

Overview

Large dataset retrieval is a strategy for retrieving large datasets by fetching records in smaller, more manageable batches. Mule Enterprise provides the key components and transformers needed to implement a wide range of these strategies.

When To Use It
  • When the dataset to be retrieved is large enough to overwhelm memory and connection resources.
  • When preserving the order of messages is important.
  • When resumable processing is desired (that is, retrieval of the dataset can pick up where it left off, even after service interruption).
  • When load balancing the data retrieval among clustered Mule nodes.
How It Works

Large dataset retrieval does not use conventional inbound SELECT queries to retrieve data. Instead, it uses a Batch Manager component to compute ID ranges for the next batch of records to be retrieved. An outbound SELECT query uses this range to actually fetch the records. The Batch Manager also controls batch processing flow to make sure that it does not process the next batch until the previous batch has finished processing.

Detailed usage of the large dataset retrieval feature is shown in JDBC Example #4.

Important Limitations

Large dataset retrieval requires that:

  1. The source data contains a unique, sequential numeric ID. Records should also be fetched in ascending order with respect to this ID.
  2. There are no large gaps in these IDs (no larger than the configured batch size).
In Combination with Batch Inserts

Combining large dataset retrieval with batch inserts can support simple but powerful ETL use cases. See Example #4 and JDBC Transport Performance Benchmark Results for more details on how Mule can be used to transport millions of records an hour from one database table to another.

Acknowledgment (ACK) Statements

ACK statements are optional SQL statements that are paired with inbound SELECT queries. When an inbound SELECT query is invoked by Mule, the ACK statement is invoked for each record returned by the query. Typically, the ACK statement is an UPDATE, INSERT, or DELETE.

Continuing the inbound SELECT query example above, the ACK statement would be configured as follows:

...
<jdbc:connector name="jdbcConnector" pollingFrequency="10000" dataSource-ref="jdbcDataSource">

    <jdbc:query key="selectLoadedMules"
          value="SELECT ID, MULE_NAME, RANCH, COLOR, WEIGHT, PROCESSED from mule_source where ID between 0 and 20"/>
    <jdbc:query key="selectMules.ack"
          value="update mule_source set PROCESSED='Y'  where ID = #[map-payload:ID] "/>        

</jdbc:connector>
...

Notice the convention of appending an ".ack" extension to the query name. This convention lets Mule know which inbound SELECT query to pair with the ACK statement.

Also, note that the ACK statement supports parameters. These parameters are bound to any of the column values from the inbound SELECT query (such as #[ID] in the case above).

ACK statements are useful when you want an inbound SELECT query to retrieve records from a source table no more than once. Be careful, however, when using ACK statements with larger result sets. As mentioned earlier, an ACK statement gets issued for each record retrieved, and this can be very resource-intensive for even a modest number of records per second (> 100).

Basic Insert/Update/Delete Statements

SQL INSERT, UPDATE, and DELETE statements are specified on outbound endpoints. These statements are typically configured with parameters, which are bound with values passed along to the outbound endpoint from an upstream component.

Basic statements execute just one statement at a time, as opposed to batch statements, which execute multiple statements at a time. Basic statements are appropriate for low-volume record processing (<20 records per second), while batch statements are appropriate for high-volume record processing (thousands of records per second).

For example, when a message with a java.util.Map payload is sent to a basic insert/update/delete endpoint, the parameters in the statement are bound with corresponding entries in the Map. In the configuration below, if the message contains a Map payload with {ID=1,TYPE=1,DATA=hello,ACK=0}, the following insert will be issued: "INSERT INTO TEST (ID,TYPE,DATA,ACK) values (1,1,'hello',0)".

<jdbc:connector name="jdbcConnector" pollingFrequency="10000" dataSource-ref="jdbcDataSource">
    <jdbc:query key="outboundInsertStatement"
              value="INSERT INTO TEST (ID, TYPE, DATA, ACK) VALUES (#[map-payload:ID], 
                    #[map-payload:TYPE],#[map-payload:DATA], #[map-payload:ACK])"/>
</jdbc:connector>
...
<model name="ExampleModel">
    <service name="outboundInsertExample">
        <inbound>
            <inbound-endpoint address="vm://doInsert"/>
        </inbound>
        <outbound>
            <pass-through-router>
               <jdbc:outbound-endpoint queryKey="outboundInsertStatement"/>
            </pass-through-router>
        </outbound>
    </service>
</model>
...

Batch Insert/Update/Delete Statements

As mentioned above, batch statements represent a significant performance improvement over their basic counterparts. Records can be inserted at a rate of thousands per second with this feature.

Usage of batch INSERT, UPDATE, and DELETE statements is the same as for basic statements, except the payload sent to the VM endpoint should be a List of Maps, instead of just a single Map.

Examples #1 and #4 demonstrate this feature. Batch statements are available in Mule Enterprise only.

Batch Callable Statements are also supported. Usage is identical to Batch Insert/Update/Delete.

Advanced JDBC-related Transformers

Common integration use cases involve moving CSV and XML data from files to databases and back. This section describes the transformers that perform these actions. These transformers are available in Mule Enterprise only.

XML-JDBC Transformer

The XML Transformer converts between XML and JDBC-format Maps. The JDBC-format Maps can be used by JDBC outbound endpoints (for select, insert, update, or delete operations).

Transformer Details:

NameClassInputOutput
XML -> Mapsorg.mule.providers.jdbc.transformers.XMLToMapsTransformerjava.lang.String (XML)java.util.List
(List of Maps. Each Map corresponds to a "record" in the XML.)
Maps -> XMLorg.mule.providers.jdbc.transformers.MapsToXMLTransformerjava.util.List
(List of Maps. Each Map will be converted into a "record" in the XML)
java.lang.String (XML)

Also, the XML message payload (passed in or out as a String) must adhere to a particular schema format:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="table">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="record"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="record">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="field"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="field">
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base="xs:NMTOKEN">
          <xs:attribute name="name" use="required" type="xs:NCName"/>
          <xs:attribute name="type" use="required" type="xs:NCName"/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>
</xs:schema>

Here is an example of a valid XML instance:

<table>
    <record>
	<field name="id" type="java.math.BigDecimal">0</field>
	<field name="name" type="java.lang.String">hello</field>
    </record>
</table>

The transformer converts each "record" element to a Map of column/value pairs using "fields". The collection of Maps is returned in a List.

See Example #2, which uses the XML Transformer to convert results from a database query into an XML document.

CSV-JDBC Transformer

The CSV Transformer converts between CSV data and JDBC-format Maps. The JDBC-format Maps can be used by JDBC outbound endpoints (for select, insert, update, or delete operations).

Transformer Details:

NameClassInputOutput
CSV -> Mapsorg.mule.providers.jdbc.transformers.CSVToMapsTransformerjava.lang.String
(CSV data)
java.util.List
(List of Maps. Each Map corresponds to a "record" in the CSV)
Maps -> CSVorg.mule.providers.jdbc.transformers.MapsToCSVTransformerjava.util.List
(List of Maps. Each Map will be converted into a "record" in the CSV)
java.lang.String
(CSV data)

The following table summarizes the properties that can be set on this transformer:

PropertyDescription
delimiterThe delimiter character used in the CSV file. Defaults to comma.
qualifierThe qualifier character used in the CSV file. Used to signify if text contains the delimiter character.Defaults to double quote.
ignoreFirstRecordInstructs transformer to ignore the first record. Defaults to false.
mappingFileLocation of Mapping file. Required. Can either be physical file location or classpath resource name. The DTD format of the Mapping File can be found at: http://flatpack.sourceforge.net/flatpack.dtd. For examples of this format, see http://flatpack.sourceforge.net/documentation/index.html.

For an example, see Example #1, which uses the CSV Transformer to load data from a CSV file to a database table.

Outbound SELECT Queries

An inbound SELECT query is invoked on an inbound endpoint according to a specified polling frequency. A major improvement to the inbound SELECT query is the outbound SELECT query, which can be invoked on an outbound endpoint. As a result, the outbound SELECT query can do many things that the inbound SELECT query cannot, such as:

  1. Support synchronous invocation of queries. For example, you can implement the classic use case of a web page that serves content from a database using an HTTP inbound endpoint and an outbound SELECT query endpoint.
  2. Allows parameters so that values can be bound to the query at runtime. This requires that the message contain a Map payload containing key names that match the parameter names. For example, the following configuration could be used to retrieve an outbound SELECT query:
    ...
    <jdbc:connector name="jdbcConnector" dataSource-ref="jdbcDataSource">
            <jdbc:query key="selectMules"
                        value="select * from mule_source where ID between 0 and #[map-payload:ID]"/>
    </jdbc:connector>
    ...
    <model name="ExampleModel">
        <service name="selectOutboundExample">
            <inbound>
                <inbound-endpoint address="vm://mapReceiver"/>
            </inbound>
            <outbound>
                <pass-through-router>
                   <jdbc:outbound-endpoint queryKey="selectMules"/>
                </pass-through-router>
            </outbound>
        </service>
    </model>
    
    

    In this scenario, if a Map is sent to the vm://mapReceiver endpoint containing this key/value pair:

    key=ID
    value=3
    

    The following query is executed:

    SELECT * FROM mule_source WHERE ID between 0 and 3
    

    See Examples #2 and #3 for further outbound SELECT query examples. Note that this feature is available in Mule Enterprise only.

Outbound Stored Procedure Support - Basic

Stored procedures are supported on outbound endpoints in Mule. Like any other query, stored procedure queries can be listed in the queries map. Following is an example of how stored procedure queries could be defined:

<jdbc:connector name="jdbcConnector" pollingFrequency="10000" dataSource-ref="jdbcDataSource">
    <jdbc:query key="storedProc" value="CALL addField()"/>
</jdbc:connector>

To denote that we are going to execute a stored procedure and not a simple SQL query, we must start off the query by the text CALL followed by the name of the stored procedure.

Parameters to stored procedures can be forwarded by either passing static parameters in the configuration or using the same syntax as for SQL queries (see "Passing in Parameters" below). For example:

<jdbc:query key="storedProc1" value="CALL addFieldWithParams(24)"/>
<jdbc:query key="storedProc2" value="CALL addFieldWithParams(#[map-payload:value])"/>

...
<pass-through-router>
    <jdbc:outbound-endpoint queryKey="storedProc1"/>
</pass-through-router>
...
<pass-through-router>
    <jdbc:outbound-endpoint address="jdbc://storedProc2?value=25"/>
</pass-through-router>
...

If you do not want to poll the database, you can write a stored procedure that uses HTTP to start a Mule service. The stored procedure can be called from an Oracle trigger. If you take this approach, make sure the Mule service is asynchronous. Otherwise, the trigger/transaction won't commit until the HTTP post returns.

Note that stored procedures are only supported on outbound endpoints. If you want to set up a service that calls a stored procedure at a regular interval, you can define a Quartz inbound endpoint and then define the stored procedure call in the outbound endpoint. For information on using Quartz to trigger services, see the following blog post.

Passing in Parameters

To pass in parameter values and get returned values to/from stored procedures or stored functions in Oracle, you declare the parameter name, direction, and type in the JDBC query key/value pairs on JDBC connectors using the following syntax:

Call #[<return parameter name>;<int | float | double | string | resultSet>;<out>] := 
<Oracle package name>.<stored procedure/function name>($PARAM1, $PARAM2, ...)

where $PARAMn is specified using the following syntax:

#[<parameter name>;<int | float | double | string | resultSet>;<in | out | inout>]

For example:

<jdbc:query key="SingleCursor"  value="call MULEPACK.TEST_CURSOR(#[mules;resultSet;out])"/>

This SQL statement calls a stored procedure TEST_CURSOR in the package of MULEPACK, specifying an out parameter whose name is "mules" of type java.sql.ResultSet.

Here is another example:

<jdbc:query key="itcCheckMsgProcessedOrNot"

value="call #[mules;int;out] := ITCPACK.CHECK_IF_MSG_IS_HANDLED_FNC(487568,#[mules1;string;out],
#[mules2;string;out],#[mules3;int;out],#[mules4;string;out])"/>

This SQL statement calls a stored function CHECK_IF_MSG_IS_HANDLED_FNC in the package of ITCPACK, assigning a return value of integer to the parameter whose name is "mules" while specifying other parameters, e.g., parameter "mules2" is a out string parameter.

Stored procedures/functions can only be called on JDBC outbound endpoints. Once the values are returned from the database, they are put in a java.util.HashMap with key/value pairs. The keys are the parameter names, e.g., "mules2", while the values are the Java data values (Integer, String, etc.). This hash map is the payload of MuleMessage either returned to the caller or sent to the next endpoint depending on the Mule configuration.

Outbound Stored Procedure Support - Advanced

Mule Enterprise provides advanced stored procedure support for outbound endpoints beyond what is available in the Mule community release. This section describes the advanced support.

OUT Parameters

In Mule Enterprise, you can execute your stored procedures with out and inout scalar parameters. The syntax for such parameters is:

<jdbc:query key="storedProc1" value="CALL myProc(#[a], #[b;int;inout], #[c;string;out])"/>

You must specify the type of each output parameter (OUT, INOUT) and its data type (int, string, etc.). The result of such stored procedures is a map containing (out parameter name, value) entries.

See Example #3 for more examples.

Oracle Cursor Support

For Oracle databases only, an OUT parameter can return a cursor. The following example shows how this works.

If you want to handle the cursor as a java.sql.ResultSet, see the "cursorOutputAsResultSet" service below, which uses the "MapLookup" transformer to return the ResultSet.

If you want to handle the cursor by fetching the java.sql.ResultSet to a collection of Map objects, see the "cursorOutputAsMaps" service below, which uses both the "MapLookup" and "ResultSet2Maps" transformers to achieve this result.

<jdbc:connector name="jdbcConnector" pollingFrequency="1000" cursorTypeConstant="-10"
      dataSource-ref="jdbcDataSource">
    <jdbc:query key="SingleCursor"  value="call TEST_CURSOR(#[mules;resultSet;out])"/>
</jdbc:connector>
    
<custom-transformer class="org.mule.transformer.simple.MapLookup" name="MapLookup">
    <spring:property name="key" value="mules"/>    
</custom-transformer>
    
<jdbc:resultset-to-maps-transformer name="ResultSet2Maps"/>
        
    <model name="SPModel">       
        <service name="cursorOutputAsMaps">
            <inbound>
                <vm:inbound-endpoint path="returns.maps" responseTransformer-refs="ResultSet2Maps MapLookup"/>
            </inbound>
            <outbound>
                <pass-through-router>
                    <jdbc:outbound-endpoint queryKey="SingleCursor"/>
                </pass-through-router>
            </outbound>
        </service>
        
        <service name="cursorOutputAsResultSet">
            <inbound>
                <vm:inbound-endpoint  path="returns.resultset"  responseTransformer-refs="MapLookup"/>
            </inbound>
            <outbound>
                <pass-through-router>
                    <jdbc:outbound-endpoint queryKey="SingleCursor"/>
                </pass-through-router>
            </outbound>
        </service>       
    </model>    

In the above example, note that it is also possible to call a function that returns a cursor ref. For example, if TEST_CURSOR2() returns a cursor ref, the following statement could be used to get that cursor as a ResultSet:

    <jdbc:query key="SingleCursor"  value="call #[mules;resultSet;out] := TEST_CURSOR2()"/>
Important note on transactions: When calling stored procedures or functions that return cursors (ResultSet), it is recommended that you process the ResultSet within a transaction.

Unnamed Queries

SQL statements can also be executed without configuring queries in the Mule configuration file. For a given endpoint, the query to execute can be specified as the address of the URI.

MuleMessage msg = eventContext.requestEvent("jdbc://SELECT * FROM TEST", 0);

Flexible Data Source Configuration

You can use any JDBC data source library with the JDBC Connector. The "myDataSource" reference below refers to a DataSource bean created in Spring:

<jdbc:connector name="jdbcConnector" pollingFrequency="10000" dataSource-ref="myDataSource">
        ...
</jdbc:connector>

You can also create a JDBC connection pool so that you don't create a new connection to the database for each message. You can easily create a pooled data source in Spring using xapool. The following example shows how to create the Spring bean right in the Mule configuration file.

<spring:bean id="pooledDS" class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
  <spring:property name="driverName" value="oracle.jdbc.driver.OracleDriver"/>
  <spring:property name="url" value="jdbc:oracle:thin:user/pass@host:1521:db"/>
</spring:bean>

If you need more control over the configuration of the pool, you can use the standard JDBC classes. For example, you could create the following bean in the Spring configuration file (you could also create them in the Mule configuration file by prefixing everything with the Spring namespace):

<bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> 
        <property name="driverClass"> 
            <value>oracle.jdbc.driver.OracleDriver</value> 
        </property> 
        <property name="jdbcUrl"> 
            <value>jdbc:oracle:thin:@MyUrl:MySID</value> 
        </property> 

        <property name="user"> 
            <value>USER</value> 
        </property> 
        <property name="password"> 
            <value>PWD</value> 
        </property> 

        <property name="properties"> 
            <props> 
                <prop key="c3p0.acquire_increment">5</prop> 
                <prop key=" c3p0.idle_test_period">100</prop> 
                <prop key="c3p0.max_size">100</prop> 
                <prop key="c3p0.max_statements">1</prop> 
                <prop key=" c3p0.min_size">10</prop> 
                <prop key="user">USER</prop> 
                <prop key="password">PWD</prop> 
            </props> 
        </property> 
    </bean>

You could then reference the c3p0DataSource bean in your Mule configuration:

<connector name="C3p0Connector" className="org.mule.providers.jdbc.JdbcConnector"> 
  <properties> 
    <container-property name="dataSource" reference="c3p0DataSource"/> 
      <map name="queries"> 
        <property name="test1" value="select * from Tablel"/> 
        <property name="test2" value="call testd(1)"/> 
      </map> 
  </properties> 
</connector> 

Or you could call it from your application as follows:

JdbcConnector jdbcConnector = (JdbcConnector) MuleServer.getMuleContext().getRegistry().lookupConnector("C3p0Connector"); 
ComboPooledDataSource datasource = (ComboPooledDataSource)jdbcConnector.getDataSource(); 
Connection connection = (Connection)datasource.getConnection(); 

String query = "select * from Table1"; //any query
Statement stat = connection.createStatement();
ResultSet rs = stat.executeQuery(query);

To retrieve the data source from a JNDI repository, you would configure the connector as follows:

<spring:beans>
  <jee:jndi-lookup id="myDataSource" jndi-name="yourJndiName" environment-ref="yourJndiEnv" />
  <util:map id="jndiEnv">
    <spring:entry key="java.naming.factory.initial" value="yourJndiFactory" />
   </util:map>
</spring:beans>

If you create the Spring bean right in the Mule configuration file, you must include the following namespaces:

<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:spring="http://www.springframework.org/schema/beans"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:jdbc="http://www.mulesource.org/schema/mule/jdbc/2.2"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
       http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
       http://www.mulesource.org/schema/mule/jdbc/2.2 http://www.mulesource.org/schema/mule/jdbc/2.2/mule-jdbc.xsd">

Transactions

Transactions are supported on JDBC endpoints. See Transaction Management for details.

API Documentation and Notes

Connector Properties

You can set the following properties on the JDBC connector.

PropertyDescriptionDefaultRequired
dataSource-refReference to the JDBC data source to use. When using XA transactions, an XADataSource object must be provided. Yes
pollingFrequencyThe delay in milliseconds that will be used during two subsequent polls to the database No
resultSetHandler-refReference to ResultSetHandler used to pass back query results. For more information about this object, see the examples.org.apache.commons.dbutils.
handlers.MapListHandler
No
queryRunner-refReference to the QueryRunner to use when executing a Query. For more information about this object, see the examples.org.apache.commons.dbutils.
QueryRunner
no
transactionPerMessageWhether each database record should be received in a separate transaction. If false, there will be a single transaction for the entire result set.trueNo

Extending the SQL Strategy

As of Mule 2.2, you can use the <sqlStatementStrategyFactory> child element to override the default SqlStatementStrategyFactory using the class or ref attribute. It determines the execution strategy based on the SQL provided. For example:

<jdbc:connector name="jdbcConnector4" dataSource-ref="testDS2">
  <jdbc:sqlStatementStrategyFactory class="org.mule.transport.jdbc.config.JdbcNamespaceHandlerTestCase$TestSqlStatementStrategyFactory"/>
</jdbc:connector>

<jdbc:connector name="jdbcConnector5" dataSource-ref="testDS2">
  <jdbc:sqlStatementStrategyFactory ref="sqlStatementStrategyFactory"/>
</jdbc:connector>

Notes on Configuring Queries

SQL queries are used by endpoints and should be configured on the connector using the "query" element:

<jdbc:query key="myQuery" value="select * from blah"/>

The queries can be parameterized using the #[...] pattern that follows the Expression Evaluation Framework.

Runnable Examples

For examples of using the Mule Enterprise version of the JDBC transport, see JDBC Transport Examples.

Performance Results

For information on performance testing on the Mule Enterprise version of the JDBC transport, see JDBC Transport Performance Benchmark Results.

Configuration Reference

For a list of the elements available in the JDBC transport schema, see JDBC Transport Configuration Reference.

Why Polling Requires at Least Two Threads

While polling happens from its own thread (created in AbstractPollingMessageReceiver.poll() ), the actual processing of the message receiver happens on the receiver's thread pool. Each poll() consumes one slot in the receiver thread pool. The poll() method in TransactedPollingMessageReceiver schedules work to the same receiver thread pool if results are not received in a transaction, which is the case here. Since the receiver thread pool's size is only 1 and the poll() method that's currently running already uses that slot, the wait policy kicks in and eventually fails adding the work item.

By specifying the receiveMessageInTransaction and receiveMessagesInXaTransaction endpoint properties and configuring the connector to not use a transaction per message you get the desired behavior

详解:hive启动hiveserver2连JDBC报错:Could not open client transport with JDBC Uri 解决方案 hive启动hiveserver2连JDBC报错:Could not open client transport with JDBC Uri 解决方案 [hadoop@hadoop001 bin]$ ./beeline -u jdbc:hive2://hadoop001:10000/default -n hadoop ls: cannot access /home/hadoop/app/spar... 阅读详情

相关推荐

Hive连接报错:Could not open client transport with JDBC Uri: jdbc:hive2://192.168.216.128:10000

Hive连接报错: Could not open client transport with JDBC Uri: jdbc:hive2://192.168.216.128:10000: java.net.ConnectException: Connection refused: connect java.net.ConnectException: Connection refused: connect java.net.ConnectException: Connection refused: connec

zhengzaifeidelushang的博客 5299

mule进阶之jdbc transport

本文在我的javaeyeblog地址如下:http://lcllcl987.javaeye.com/blog/350502同步更新。 继续在mule的xml汪洋中遨游。向一个vm:queue发送map消息, mule根据map信息, 动态执行sql, 并返回数据.select 的查询mule默认返回map数据.配置文件:<mule xmlns="http://www.mules

lcllcl987的专栏 2510

C# CAD2016 多边形顶点按方向重新排序

这样,通过以上步骤,我们找到了一个多边形的一个候选起始顶点(可能位于西北方向),并且已经获取了该多边形的边界框信息,这些信息对于后续判断顶点排列顺序及处理其他相关问题具有重要意义。完整地处理八个方向(东北、东南、西南、西北、北、南、东、西),我们可以创建一个方法来获取多边形相对于给定点的最近顶点及其对应的方向。对象(或类似的多边形表示方式),其中包含了多边形的顶点。//附送AI 图片无版权 随意用 龙年大吉大利。

转眼之间 一路有你 1356

运行代码生成器时出错,“获取类型”,请尝试重新生成项目

我们在创建Models后,去创建Controllers总是出现这个问题,不是因为代码编写而是vs本身的一个问题:vs的bug吧,生成执行文件的时候出错了,叫你重新生成解决方案试试 右键解决方案,然后重新生成就可以了,亏我找了很多人还有很多插件 ...

qq_43644023的博客 1988

Zotero插件安装保姆级教程:从Jasminum到Sci-Hub,一站式搞定文献管理

本文提供Zotero插件安装的保姆级教程,从Jasminum到Sci-Hub,一站式搞定文献管理。通过详细配置和实战案例,帮助用户高效构建文献工作流,提升研究效率。重点介绍了元数据抓取、PDF管理、文献分析和知识产出等关键插件的使用方法。

weixin_42531516的博客 171

TouchSocket TcpService:构建高性能Tcp服务的终极利器

/ 接收到的数据data");// 回复客户端await ((ITcpSessionClient)client).SendAsync("服务端已收到消息!");// 继续执行后续插件TouchSocket的TCPService以极简的API、强大的扩展性和卓越的性能,重新定义了.NET TCP服务的开发体验。无论是物联网平台还是金融级实时通信系统,TCPService均能提供可靠的基础设施支持。立即探索示例项目,开启你的高性能服务开发之旅!扩展阅读如何实现WebSocket服务?

若汝棋茗 的博客 1461

从properties文件和数据库读取配置项

在《@Value值注入及配置文件组件扫描方式》这篇blog中,说过从properties文件读取配置项,然后通过@Value进行注入时需要注意的问题。实际上,有时候不光从properties文件中读取配置项,还要从数据库中读取配置项。从数据库中读取配置项可以通过PropertyPlaceholderConfigurer的子类来实现。 假设数据源配置在spring-datasource-local.

xiaoyi52的专栏 1422

以太网以及车载以太网概述

千兆网线和百兆网线区别 1、所谓的百兆网线其实就是 五类线 和超五类线 ,而千兆网线主要是指六类线 和超六类线 ,另外还有古老的十兆网线也就是指 四类线 和 三类线 等。 2、在使用上,其实千兆网线和百兆网线是没什么区别的,千兆网线完全兼容百兆网络。 3、百兆网线的线芯是8芯,但上传和下载只用到了其中的4根,而千兆网线需要完全用到8根。 4、另外在线芯的排布上,千兆网线的线芯中间有个十字形的塑料架,用来把四组8芯的线分开,这个百兆网线是没有的, 5、所有的网线在外皮上都有种类标识,CAT5 CAT

$好记性还是要多记录$ 4074

JDBC Transport Examples

This page describes the examples you can run for the Mule Enterprise JDBC transport. These examples are designed to work with Oracle databases only. Setup The Mule Enterprise JDBC Examples are loc

borhunter的专栏 966

基于深度学习的中文方言识别模型训练实战

本文介绍了一个基于深度学习的中文方言识别模型开发流程。项目采用PyTorch框架和Chinese-BERT-wwm预训练模型,构建了包含BERT基础层、方言特征增强层和注意力机制的多方言分类系统。文中详细阐述了数据收集策略,包括从社交媒体、语料库和众包平台获取多源数据,并实现了文本清洗、同义词替换和回译等数据增强技术。模型架构部分展示了如何在BERT基础上添加方言特征提取层和多头注意力机制来提升识别性能。该方案支持普通话、粤语等6种主要方言的识别,目标准确率达90%以上,响应时间小于100ms,适用于智能客

电脑管家 1730

操作系统实验四 进程运行轨迹的跟踪与统计(哈工大李治军)

实验4 进程运行轨迹的跟踪与统计 实验目的 掌握 Linux 下的多进程编程技术; 通过对进程运行轨迹的跟踪来形象化进程的概念; 在进程运行轨迹跟踪的基础上进行相应的数据统计,从而能对进程调度算法进行实际的量化评价,更进一步加深对调度和调度算法的理解,获得能在实际操作系统上对调度算法进行实验数据对比的直接经验。 实验内容 进程从创建(Linux 下调用 fork())到结束的整个过程就是进程的生命期,进程在其生命期中的运行轨迹实际上就表现为进程状态的多次切换,如进程创建以后会成为就绪态;当该进程被调度以

leoabcd12的博客 4653

报错Error: Could not open client transport with JDBC Uri: jdbc:hive2://hadoop102:10000: Failed to open

第一步启动 hadoop集群 第二步启动:(远程连接服务) 第三步启动:(元数据)可断开 第四步启动: 第五建立对外端口: 第六步连接DataGrip 解决报错方案: 在hadoop中/etc/hadoop/core-site.xml(/opt/module/hadoop-3.1.3/etc/hadoop/core-site.xml)增加如下配置 <name>hadoop.proxyuser.xxx.hosts</name> <va.

Sdwq12的博客 3682

后仿真中《SDF反标必懂连载篇》之 <INTERCONNECT/IOPATH> 到底反标电路路径是哪里

对于SDF INTERCONNECT ENTRY 描述,我们在之前的文章有详解。读万卷书,行万里路。实践很重要。今天,搞一下SDF INTERCONNECT / IOPATH 延迟数据信息,究竟反标的是哪一路径延时?究竟在电路上一段段如何表现出延迟现象的呢?

那么菜的博客 2133

mule进阶之jdbc transport:

简单需求如下:向一个vm:queue发送map消息, mule根据map信息, 动态执行sql, 并返回数据. select 的查询mule默认返回map数据. 配置文件:my-mule-jdbc-config.xml如下: Xml代码   xml version="1.0" encoding="UTF-8"?>  mule xmlns="http://www.mule

borhunter的专栏 1143

【技能】OpenClaw Skills学习及手搓一个极简skill

本文介绍了OpenClaw Skills的基础概念与使用方法。Skills是OpenClaw代理使用工具的核心载体,通过SKILL.md文件定义技能属性和执行方式。技能加载遵循"工作区>本地>内置>自定义目录"的优先级规则。用户可通过ClawHub一键安装现成技能,也可自定义开发技能:创建技能目录,编写包含YAML元数据和执行指令的SKILL.md文件,放置于工作区skills目录进行测试。文章还介绍了多代理场景下的技能共享、插件集成以及安全注意事项,包括沙箱使用和敏感

海兰 3976

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Root cause be too many concurrent connections error could not open clinet transport with jdbc uri

一:出现的现象 beeline连接数据库报错Could not open client transport with JDBC Uri: jdbc:hive2://localhost:10000/cr: java.n 二:分析 出现这种错误: error could not open clinet transport with jdbc uri 本来是想是不是配置出现了问题 于是就去检查了一下配...

qq_43688472的博客 2119

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

hive启动hiveserver2连JDBC报错:Could not open client transport with JDBC Uri解决方案

开启hiveserver2和beeline后jdbc报错Could not open client transport with JDBC Uri 0: jdbc:hive2://hadoop100:10000(closed)&gt; 报错信息 Error: Could not open client transport with JDBC Uri: jdbc:hive2://had...

攻城狮Kevin 1万+

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Error: Could not open client transport with JDBC Uri: jdbc:hive2://

如果你的 Hive 设置需要认证(如 Kerberos),确保你的连接字符串包含了正确的认证参数,例如。查看 HiveServer2 的日志和你的应用程序的日志,这可能会提供更多关于为什么连接失败的线索。),并且你的用户有权限访问 Hive 数据库。确保 Hive 配置允许从你的客户端地址连接。确保你的项目中已经正确添加了 Hive JDBC 驱动。对于 Hive,通常使用的是。确认你的应用程序可以访问 Hive 服务器的网络地址和端口。确保你的 JDBC 连接字符串格式正确。

chimchim66的博客 731

Error: Could not open client transport with JDBC Uri

Error: Could not open client transport with JDBC Uri: jdbc:hive2://farm1:10000: Failed to open new session: java.lang.RuntimeException: org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: root is not al

weixin_41877582的博客 3216

Could not open client transport with JDBC Uri: jdbc:hive2://hadoop102:10000

使用 JDBC 方式访问 Hive时启动hiveserver2报错 Could not open client transport with JDBC Uri: jdbc:hive2://hadoop102:10000: java.net.ConnectException: 拒绝连接 (Connection refused) (state=08S01,code=0) 原因是hiveserver2没有完全启动,需要多等待几分钟。 如果还没有解决: 修改hadoop 配置文件 先切换...

weixin_57597001的博客 2837

Could not open client transport with JDBC Uri hive jdbc connection refused

2020/03/23 15:08:42-[INFO]-[org.apache.hive.jdbc.Utils.parseURL(Utils.java:285)]-Supplied authorities: 172.18.6.1:10000 2020/03/23 15:08:42-[INFO]-[org.apache.hive.jdbc.Utils.parseURL(Utils.java:372)]...

zztSky 1388

Error: Could not open client transport with JDBC Uri 解决方案

这里写自定义目录标题错误现象解决方案 错误现象 [root@cpucode100 bin]# beeline -u jdbc:hive2://cpucode100:10000 -n root Connecting to jdbc:hive2://cpucode100:10000 21/12/15 21:41:51 [main]: WARN jdbc.HiveConnection: Failed to connect to cpucode100:10000 Error: Could not open cli

记录点点滴滴 3万+
上一篇: Mule的JDBC应用1
下一篇: JDBC Transport Examples
borhunter
博客等级 码龄20年 4粉丝 3原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值