Missing Oracle jdbc Driver for Mule ESB Datamapper - jdbc

Good morning to everyone,
I have a big issue to run a job in Mule ESB. I'm trying to map an CSV file in a table of an oracle database. To do that, I created a JDBC Connector with a Oracle DataSource and the Connection Test is Valid. But if i run The Job an error Message appears.
[Error Message]
-------------------------------------
ERROR 2015-06-17 09:01:26,223 [[....].connector.file.mule.default.receiver.01] org.mule.exception.DefaultMessagingExceptionStrategy:
******************************************************************************
Message : com.mulesoft.mule.module.datamapper.api.exception.DataMapperCreationException: Element [JDBC0:]-Can't initialize connection DBConnection driver[null]:jndi[null]:url[jdbc:oracle:thin:#.....:....:.......]:user[......]. (java.lang.RuntimeException). Message payload is of type: ReceiverFileInputStream
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Cannot load class 'oracle.jdbc.OracleDriver' (java.lang.ClassNotFoundException)
org.mule.module.launcher.application.CompositeApplicationClassLoader:74 (null)
2. Cannot create JDBC driver 'Oracle'. Cannot find class. (org.jetel.exception.ComponentNotReadyException)
org.jetel.connection.jdbc.driver.JdbcDriverImpl:188 (null)
3. Can't initialize connection DBConnection driver[null]:jndi[null]:url[..............]:user[.......]. (org.jetel.exception.ComponentNotReadyException)
org.jetel.graph.TransformationGraph:413 (null)
4. Element [JDBC0:]-Can't initialize connection DBConnection driver[null]:jndi[null]:url[..............]:user[...........]. (com.mulesoft.mule.module.datamapper.api.exception.DataMapperCreationException)
com.mulesoft.mule.module.datamapper.clover.impl.graphfactory.DocumentCloverGraphFactoryImpl:59 (null)
5. com.mulesoft.mule.module.datamapper.api.exception.DataMapperCreationException: Element [JDBC0:]-Can't initialize connection DBConnection driver[null]:jndi[null]:url[............]:user[.....]. (java.lang.RuntimeException)
com.mulesoft.mule.module.datamapper.clover.impl.graphprovider.PoolGraphProvider:109 (null)
6. com.mulesoft.mule.module.datamapper.api.exception.DataMapperCreationException: Element [JDBC0:]-Can't initialize connection DBConnection driver[null]:jndi[null]:url[..............]:user[..............]. (java.lang.RuntimeException). Message payload is of type: ReceiverFileInputStream (org.mule.api.MessagingException)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.ClassNotFoundException: Cannot load class 'oracle.jdbc.OracleDriver'
at org.mule.module.launcher.application.CompositeApplicationClassLoader.loadClass(CompositeApplicationClassLoader.java:74)
at org.jetel.util.classloader.GreedyURLClassLoader.loadClassGreedy(GreedyURLClassLoader.java:137)
at org.jetel.util.classloader.GreedyURLClassLoader.loadClass(GreedyURLClassLoader.java:111)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
******************************************************************************
Do I have to put the driver "ojdbc7.jar" in a specific directory?

What it looks like you have configured oracle.jdbc.OracleDriver instead of oracle.jdbc.driver.OracleDriver
You can configure the following example :-
<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>
You need to configure and change as per your ip, username, password etc
Add commons-dbcp-1.2.2.jar or other version and ojdbc6.jar in your classpath as dependancy

Related

Is there a way to use environment variable in payara-resources.xml when creating connector-connection-pool

I am running an application on Payara micro and trying to create a connector-connection-pool in the payara-resources.xml file that uses environment variables to pass in data as below:
<connector-connection-pool resource-adapter-name="wmq.jmsra" name="jms/MyConnectionPool"
connection-definition-name="javax.jms.ConnectionFactory">
<property name="transportType" value="CLIENT"/>
<property name="port" value="${ENV=CONFIGURATION_PORT}"/>
<property name="channel" value="${ENV=CONFIGURATION_CHANNEL}"/>
<property name="queueManager" value="${ENV=CONFIGURATION_MANAGER}"/>
<property name="username" value="${ENV=CONFIGURATION_USERNAME}"/>
<property name="hostName" value="${ENV=CONFIGURATION_HOST}"/>
</connector-connection-pool>
However this fails with the error below, but when I hardcode the values it works fine:
... 320 more
Caused by: com.ibm.mq.connector.DetailedResourceException: MQJCA1012: Failed to create a JMS connection factory., error code: MQJCA1012 A JCA ManagedConnectionFactory object was not able to create a WebSphere MQ classes for JMS ConnectionFactory object. Check the properties of the ConnectionFactory object.
... 321 more
Caused by: com.ibm.msg.client.jms.DetailedJMSException: JMSCC0005: The specified value '${ENV=CONFIGURATION_MANAGER}' is not allowed for 'XMSC_WMQ_QUEUE_MANAGER'.
The given value is not allowed for the property specified.
...
... 324 more
In the same file, I have created a jdbc-connection-pool in a similar way but it is able to resolve the environment variable successfully work:
<jdbc-connection-pool datasource-classname="org.postgresql.ds.PGConnectionPoolDataSource"
name="my_database" res-type="javax.sql.ConnectionPoolDataSource">
<property name="port" value="5432"/>
<property name="user" value="${ENV=DB_USER}"/>
<property name="password" value="${ENV=DB_PWD}"/>
<property name="ServerName" value="${ENV=DB_HOST}"/>
<property name="DatabaseName" value="${ENV=DB_NAME}"/>
</jdbc-connection-pool>
I solved my problem by moving away from defining resources in payara-resources.xml. I created a new class and defined all the resources in Java using these annotations, #DataSourceDefinition, #ConnectionFactoryDefinition, #AdministeredObjectDefinition and #MailSessionDefinition.
So the connector-connection-pool that was giving problems ended up looking like this:
#ConnectionFactoryDefinitions({
#ConnectionFactoryDefinition(
name = "java:app/jms/MyConnectionPool",
interfaceName = "javax.jms.ConnectionFactory",
resourceAdapter = "wmq.jmsra",
properties = {
"transactionSupport=XATransaction",
"transportType=CLIENT",
"channel=${ENV=CONFIGURATION_CHANNEL}",
"queueManager=${ENV=CONFIGURATION_MANAGER}",
"hostName=${ENV=CONFIGURATION_HOST}",
"port=${ENV=CONFIGURATION_PORT}",
"username=${ENV=CONFIGURATION_USERNAME}",
}
),
// other connection pools went here...
})

How to dynamically pass the property in Spring FTP Outboud channel context xml

The FTPapplicationContext.xml has the configuration to create the beans for FTPchannel. here it takes the property values from the application.proprty. Now my question is how to dynamically set the property while on the run time.
Context.xml:
<bean id="ftpClientFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="${host}"/>
<property name="port" value="${availableServerPort}"/>
<property name="username" value="${userid}"/>
<property name="password" value="${password}"/>
</bean>
<int:channel id="ftpChannel"/>
<int-ftp:outbound-channel-adapter id="ftpOutbound"
channel="ftpChannel"
remote-directory="/temp"
session-factory="ftpClientFactory">
<int-ftp:request-handler-advice-chain>
<int:retry-advice />
</int-ftp:request-handler-advice-chain>
</int-ftp:outbound-channel-adapter>
application.prperties:
userid=Administrator
password=password
availableServerPort=21
host=Testfar
FTP code:
ConfigurableApplicationContext context =
new FileSystemXmlApplicationContext("context.xml");
MessageChannel ftpChannel = context.getBean("ftpChannel",MessageChannel.class);
File file1 = new File("test.txt");
Message<File> fileMessage = MessageBuilder.withPayload(file1).build();
ftpChannel.send(fileMessage);
context.close();
In application.properiites file, I can setup a default host address but Here I need to pass the host address dynamically based on the user input. Could you please advice me on how to achieve that. It would be great If you suggest/provide some ideas.

Running simple SELECT MS SQL Server query with JDBCTemplate using JTDS driver and c3p0 data source

I am connecting to MS SQL server with following datasource
<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close" >
<property name="driverClass" value="net.sourceforge.jtds.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:jtds:sqlserver://<server>:<port>" />
<property name="user" value="${echo_db_user}" />
<property name="password" value="${echo_db_password}" />
</bean>
<bean id="myProviderDAO" class="com.care.dao.impl.DataProviderImpl">
<property name="dataSource" ref="myDataSource" />
</bean>
public class DataProviderImpl extends JdbcDaoSupport{
public Object runQuery(String staticQuery) {
try {
return getJdbcTemplate().queryForList(staticQuery);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
staticQuery is:
Select
sender,
status_dt
FROM
ServiceTickets.dbo.trouble_ticket
WHERE
status_dt BETWEEN '02-17-2010 07:00:00' AND '04-30-2014 05:00:00'
When running this query I am getting following exception:
org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [
Select
sender,
status_dt
FROM
ServiceTickets.dbo.trouble_ticket
WHERE
status_dt BETWEEN '02-17-2010 07:00:00' AND '04-30-2014 05:00:00'
]; nested exception is java.sql.SQLException: ORA-00933: SQL command not properly ended
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:98)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
Connection is happening as I have debugged the code and it passed where connection is retrieved.
Same query If I execute on Toad (client to ms sql server) executes properly.
I have used same set of steps to connect to Qracle DB and executing its queries and it works fine, only in case of MS SQL server I am facing this issue.

Hibernate-Spring Web container error

Hello I'm new to Hibernate.
I have generated with Hibernate Tools a database access module. The generator generates the code of the DAOS and Hibernate Beans.
When I test this module in a simple Java application all works fine, but when I test it in a Spring Web application I get a very strange error. Since my module is an independent jar it should access the database without regarding the circumstance of being executed in a simple Java application or a Web application. The code of my web application is:
#Controller
#RequestMapping("/")
public class Controller implements ApplicationContextAware
{
private ApplicationContext applicationContext;
#RequestMapping(value = "/purchased/songs", method = RequestMethod.GET)
public String home(Model model)
{
SessionManager.startOperation();
ChargeTryDAOBase ctdb=new ChargeTryDAOBase();
List <ChargeTry> data=ctdb.findByRemoteId("dsfsdfsdf8");
SessionManager.endOperation();
model.addAttribute("result", "data" );
return "home";
}
#Override
public void setApplicationContext(ApplicationContext arg0) throws BeansException
{
this.applicationContext = arg0;
}
}
When running this code on Tomcat I get following error:
org.springframework.web.util.NestedServletException: Handler processing
nested exception is java.lang.NoSuchMethodError:
org.hibernate.SessionFactory.getCurrentSession()Lorg/hibernate/Session;
.....
java.lang.NoSuchMethodError:
org.hibernate.SessionFactory.getCurrentSession()Lorg/hibernate/Session;
When I change some Hibernate dependencies I get following error:
java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
When I test the above code in a simple Java application all works fine.
Is this a spring-hibernate configuration problem?
Thank you for your help.
Please study
1: http://www.javatpoint.com/hibernate-and-spring-integration
and
2 http://viralpatel.net/blogs/spring3-mvc-hibernate-maven-tutorial-eclipse-example/
to get insight of Spring MVC and Hibernate Integration.
You can work with Hibernate Configuration file - here is the link -
Spring and hibernate.cfg.xml
But as your application is within a spring managed container, We will highly recommend to use applicationcontext.xml for better maintenance and management of codebase and performance.
thank you for your help finally I got all working. I followed your link and googled a little bit. The problem was that I didn't enable in my hibernate.cfg.xml file the datasource parameter, I also have configured C3P0 jdbc connection provider.
My final hibernate.cfg.xml file is:
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">true</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb</property>
<property name="hibernate.connection.username">userdb</property>
<property name="hibernate.connection.password">12345</property>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/mydb</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.numHelperThreads">4</property>
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">1800</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<hibernate-configuration>
<session-factory>
In my web.xml I have added following lines:
<resource-ref>
<description>This is a MySQL database connection</description>
<res-ref-name>jdbc/mydb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
In the Spring context file I have added following lines:
<beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<beans:property name="url" value="jdbc:mysql://localhost:3306/mydb"/>
<beans:property name="username" value="userdb"/>
<beans:property name="password" value="12345"/>
</beans:bean>
<beans:bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="configLocation">
<beans:value>classpath:hibernate.cfg.xml</beans:value>
</beans:property>
</beans:bean>
The strange thing is, that with the default Hibernate connection provider, the above solution didn't work but when I configured C3P0 all started to work.
Thank you for your help.

Spring Programmatic Jdbc Transaction rollback doesn't work

I use spring transaction to include a few db update operation into a single transaction. let say there 2 db updates within a single transaction. the update 1 is successful while the second fails. my problem is when such a case happens, the first db update get committed to db even though the second db update failed which leads to transaction rollback.
XML declaration:
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/test" />
<property name="username" value="test" />
<property name="password" value="test" />
</bean>
<bean id="testDao" class="dao.TestDao">
<constructor-arg >
<ref local="simpleJdbcTemplate" />
</constructor-arg>
<constructor-arg >
<ref local="txManager" />
</constructor-arg>
</bean>
java code:
public class DaoCallback extends TransactionCallbackWithoutResult {
protected void doInTransactionWithoutResult(TransactionStatus arg0) {
try{
dbUpdate1();
dbUpdate2();
}catch(Exception e){
arg0.setRollbackOnly();
}
}
i intentionally make the dbUpdate1 to success and the dbUpdate2 to fail so as the test out whether the rollback really works. When I debug through my code, i can see that the control flow run into the catch exception and the "setRollbackOnly()" method is called.
But when I check the database, I can see the change from dbUpdate1(). So please help explain what is wrong here?
Dara kok,
I've found out the problem. It's not the code i've that cause the problem. it's MySQL data storage configuration. MyISAM doesn't support transaction.
Spring should have shown some kind of error message so that developer can know that a transaction is being called on a database engine without transaction support.

Resources