MULE中的Oracle数据源配置(AnyPoint Studio)

时间:2015-06-07 08:22:14

标签: oracle oracle11g mule datasource mule-studio

我在Mule中使用此配置为oracle数据库:

    <spring:beans>               
    <spring:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="shutdown" name="Bean">
        <spring:property name="driverName" value="oracle.jdbc.driver.OracleDriver"/>
        <spring:property name="url" value="jdbc:oracle:thin:@192.168.28.129:1521:orcl"/>
        <spring:property name="user" value="username" />
        <spring:property name="password" value="123456" />
    </spring:bean>
</spring:beans>


<db:oracle-config name="Oracle_Configuration" useXaTransactions="true" dataSource-ref="dataSource"   doc:name="Oracle Configuration">

    <db:pooling-profile maxPoolSize="10" minPoolSize="5" acquireIncrement="2"/>
</db:oracle-config>

*我将ojdbc14.jar作为外部jar文件添加到我的项目中 但是当我在Anypoint Studio中测试Global Elements中的连接时,我看到了这个错误:

enter image description here

enter image description here

enter image description here

如何解决此问题?

另外我不得不说在主方法中我检查了连接并且没关系,这是Main方法结构:

    import java.sql.*;

public class Main {

    public static void main(String[] args) throws Exception {

           try {
                 Class.forName ("oracle.jdbc.driver.OracleDriver");
           } catch (ClassNotFoundException e) {
                 e.printStackTrace();
           }

            Connection conn = DriverManager.getConnection
                ("jdbc:oracle:thin:@192.168.28.129:1521:orcl", "eslami", "123456");
                                // @machineName:port:SID,   userid,  password

            Statement stmt = conn.createStatement();
            ResultSet rset = stmt.executeQuery("select * from person");
            while (rset.next())
                System.out.println (rset.getString(1) +  "  " + rset.getString(2) + "  " +  
                                    rset.getString(3) +  "  " + rset.getString(4) + "  " + 
                                    rset.getString(5));   // Print row 1
            stmt.close();
      }

}

2 个答案:

答案 0 :(得分:4)

这是你如何配置你的oracle: -

<spring:beans> 
<spring:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"    destroy-method="close"> 
        <spring:property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/> 
        <spring:property name="url" value="jdbc:oracle:thin:@192.168.28.129:1521:xe"/> 
        <spring:property name="username" value="yourUserName"/> 
        <spring:property name="password" value="yourPassword"/> 
        <spring:property name="removeAbandoned" value="true"/> 
        <spring:property name="initialSize" value="10"/> 
        <spring:property name="maxActive" value="50"/> 
        </spring:bean> 
</spring:beans>

<db:generic-config name="Database_Configuration" dataSource-ref="dataSource" doc:name="Generic Database Configuration" />

 <flow name="mainFlow">
     <http:listener config-ref="httpListenerConfig" path="/*" doc:name="HTTP" allowedMethods="GET"/> 
///////////////////////////////////////

Your Code
////////////////////////////////////
 <db:select config-ref="Database_Configuration" doc:name="Database">
    <db:parameterized-query><![CDATA[select * from yourtableName]]></db:parameterized-query>
</db:select>
</flow>

您可以使用上述配置并根据您的IP,用户名,密码等进行更改

不要忘记在类路径中添加commons-dbcp-1.2.2.jar或其他版本和ojdbc6.jar

答案 1 :(得分:0)

与您工作的Java示例和非工作的mule代码的一个明显区别是XATransactions。你可以尝试关掉它们,看看是否有区别吗?

否则,请提供您的Anypoint和Mule版本,我将为此代码提供测试。