I have a requirement to pull the data from database using java component in mule studio. That is Http>SOAP>Java Component(here in main class I will be giving the DB query to get details from my database)>SOAP>http sending request in xml and getting response in xml. I am getting a response when I use hardcoded values in java class ,but when trying to get from Database facing problems. Help would be greatly appreciated.
below is the part of my java code
String url = "jdbc:oracle:thin:@localhost:1521:XE";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(url, "uname", "pwd");
Statement st = conn.createStatement();
ResultSet result= st.executeQuery("select * from mule.tablename");
while(result.next())
{
long quoteId = result.getLong("quote_id");
if(parameters.getQuote().getQuoteId() == quoteId)
{
QuoteResponseType quoteresp = new QuoteResponseType();
quoteresp.supplierId = result.getString("supplier_id");
quoteresp.respFreightAmount = result.getDouble("resp_freight_amount");
quoteresp.respTaxAmount = result.getDouble("resp_tax_amount");
quoteresp.supplierQuoteNumber = result.getString("supplier_quote_no");
al.add(quoteresp);
}
NewQuoteResponse.quote.quoteResponse = al;
}
Thanks in advance.
You can use in your Mule flow and inject using lookupConnector
in your Java implementation class as follows :-
<spring:beans>
<spring:bean id="DB_Source" name="DB_Source"class="org.enhydra.jdbc.standard.StandardDataSource">
<spring:property name="url" value="${url}"/>
<spring:property name="driverName" value="${driverName}"/>
</spring:bean>
</spring:beans>
<jdbc-ee:connector name="Database_Global" dataSource-ref="DB_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database">
<jdbc-ee:query key="RetriveQuery" value="select * from mule.tablename"/>
</jdbc-ee:connector>
And in your Java class you can get the access of your db component using lookupConnector
:-
jdbcConnector = (JdbcConnector) muleContext.getRegistry()
.lookupConnector("Database_Global");
我建议您在Mule xml文件中定义一个JDBC DataSource,然后将其注入Java类中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.