Reputation:
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.
Upvotes: 0
Views: 1549
Reputation: 8311
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");
Upvotes: 1
Reputation: 4015
I suggest you define a JDBC DataSource in your Mule xml file, and then inject it into your Java class.
Upvotes: 0