Camel catching jdbc exception ClassNotFound running on karaf - java

I'm trying to catch the the exception in my camel route that is thrown when jdbc can't get the connection which is
org.springframework.jdbc.CannotGetJdbcConnectionException
To do this I got the following camel blueprint route
[...]
<doTry>
<to uri="sql:UPDATE log SET field = :#value" />
<doCatch>
<exception>org.springframework.jdbc.CannotGetJdbcConnectionException</exception>
<process ref="exceptionProcessor"></process>
</doCatch>
</doTry>
[...]
But now I get
java.lang.ClassNotFoundException: org.springframework.jdbc.CannotGetJdbcConnectionException
I already tried to add the dependency
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.3.RELEASE</version>
</dependency>
in my pom.xml or to import the package in the maven-bundle-plugin
<Import-Package>org.springframework.jdbc.*;*</Import-Package>
which both didn't work.
I only can catch 'java.lang.Exception' now. How can I do this with the
org.springframework.jdbc.CannotGetJdbcConnectionException
Exception?

You are missing to connector?
Download it here for mysql
http://dev.mysql.com/downloads/connector/j/
Even though you imported jbdc from maven you still need to include the connector in maven the mysql connector is, (no need to download the link above if you use maven like below)
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
If you aren't using mysql there are other dependencies you need for connecting to different types of databases.

Related

I can't import the JDBC Client Driver from the derby package

I have a Java Derby database running in Netbeans and I'm trying to connect to it using the JDBC driver. However, I cannot import the JDBC driver specifically from the org.apache.derby package.
What I've done:
My pom.xml file contains the following Maven repo's
<!-- https://mvnrepository.com/artifact/org.apache.derby/derby -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.15.1.3</version>
<type>jar</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.derby/derbyclient -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.15.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbynet</artifactId>
<version>10.15.1.3</version>
</dependency>
The Derby db properties says the database is using the driver
as you can see here
When trying to import the JDBC driver, it is seemingly the only thing missing from the derby import list shown in this screenshot
I have also downloaded the derby.jar file and copied it directly into C:\Program Files\Java\jdk8-221\bin
I really can't understand why the JDBC driver specifically is missing.
I see that you are using release 10.15. In this release, the arrangement of the Derby distribution into jar files has changed, and this is probably affecting you.
Please read the 10.15 Release Notes very carefully, and in particular please carefully look at the section "Note for DERBY-6945" for the details of how you have to change your classpath to access the Derby JDBC driver classes.
Probably, all you have to do is to include derbyshared.jar. But please read the entire thing.

Clickhouse JDBC driver class name

Has anyone used Spring JDBC with Clickhouse? What is the driver class name?
spring.datasource.driver-class-name=<what is it?>
I guess it could be it, even though it doesn't look like any other driver class names that I have seen.
spring.datasource.driver-class-name=ru.yandex.clickhouse.ClickHouseDriver
There is also lighter and faster alternative to the official driver version - clickhouse4j. (fork of the official driver with some improvements)
You can use it like this:
spring.datasource.driver-class-name=cc.blynk.clickhouse.ClickHouseDriver
Driver was renamed due to moving vom yandex to clickhouse.com.
Clickhouse Driver
spring.datasource.driver-class-name=com.clickhouse.jdbc.ClickHouseDriver
See https://github.com/ClickHouse/clickhouse-jdbc
Also note Java Client and JDBC Driver MVN dependencies changed as well:
Maven Clickhouse Java Client
<dependency>
<groupId>com.clickhouse</groupId>
<!-- or clickhouse-grpc-client if you prefer gRPC -->
<artifactId>clickhouse-http-client</artifactId>
<version>0.3.2-patch11</version>
</dependency>
Maven Clickhouse JDBC Driver
<dependency>
<!-- please stop using ru.yandex.clickhouse as it's been deprecated -->
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.3.2-patch11</version>
<!-- use uber jar with all dependencies included, change classifier to http for smaller jar -->
<classifier>all</classifier>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
Starting 4.0.0 yandex packages will be removed and be non functional!

I have Velocity transformer issue as I have been Migrating from mule 2.2.1 to Mule 3.3.2

Hi and thank you for your help in advance.
I am trying to migrate app from Mule 2.2.1 to Standalone Mule.
Mule 2.2.1 is embeded into tomcat. Original Velocity transformer with Mule 2.2.1 works ok, but as I start using standalone Mule 3.3.2 it does not.
This is my mule-config file fragment:
<spring:bean class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<spring:property name="velocityProperties">
<spring:map>
<spring:entry key="resource.loader" value="class"/>
<spring:entry key="class.resource.loader.class" value="org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"/>
</spring:map>
</spring:property>
</spring:bean>
As I am starting mule, I get error:
Caused by: org.mule.api.MuleRuntimeException: Failed to lookup beans of type interface org.mule.api.transformer.Converter from the Spring registry
at org.mule.config.spring.SpringRegistry.internalLookupByType(SpringRegistry.java:184)
at org.mule.config.spring.SpringRegistry.lookupByType(SpringRegistry.java:171)
at org.mule.registry.AbstractRegistryBroker.lookupByType(AbstractRegistryBroker.java:160)
at org.mule.registry.MuleRegistryHelper.lookupByType(MuleRegistryHelper.java:704)
at org.mule.config.bootstrap.SimpleRegistryBootstrap.registerTransformers(SimpleRegistryBootstrap.java:322)
at org.mule.config.bootstrap.SimpleRegistryBootstrap.initialise(SimpleRegistryBootstrap.java:185)
... 40 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.ui.velocity.VelocityEngineFactoryBean#0' defined in URL [fi
rror: org/apache/velocity/exception/VelocityException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:767)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:698)
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:519)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:319)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:396)
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1164)
at org.mule.config.spring.SpringRegistry.internalLookupByType(SpringRegistry.java:178)
... 45 more
Caused by: java.lang.NoClassDefFoundError: org/apache/velocity/exception/VelocityException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2595)
at java.lang.Class.getConstructor0(Class.java:2895)
at java.lang.Class.getDeclaredConstructor(Class.java:2066)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:67)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)
I have these dependency for Spring
<dependency>
<artifactId>spring-beans</artifactId>
<groupId>org.springframework</groupId>
<version>${spring-version}</version>
</dependency>
<dependency>
<artifactId>spring-core</artifactId>
<groupId>org.springframework</groupId>
<version>${spring-version}</version>
</dependency>
<dependency>
<artifactId>spring-context</artifactId>
<groupId>org.springframework</groupId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring-version}</version>
</dependency>
spring-version is 3.3.1
Thank you for your help
It could be a class loader issue.
declare the loader.override=org.springframework.ui.velocity In mule-deploy.properties file and try (suggested in https://forums.mulesoft.com/questions/2587/sending_an_email_using_velocity_templates-2ke02.html).
Try adding velocity dependency to your pom -
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
Thank you so much for your reply.
The problem I was experiencing was not because of the dependency.
Actually it was there.
Solution was to add 2 velocity jars: velocity and velocity-tools to %MULE_HOME%/lib/user.
That solved the problem.
All specific Jars that needed for the Mule to get done something special, like transformation or JMS requires jars that should be added to the %MULE_HOME%/lib/user directory

Maven dependency does not update

I have a problem with Maven.
I used to use the 6.0.5 mysql-connector but because of some serverTime error I wanted to go back to an older version, but after that I receive:
java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
Everything stays the same only the dependency has changed:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.5</version>
</dependency>
changes to:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
Maven appears to update the jars properly, only somehow the compiler doesn't see them. Any idea what may cause the problem? When I go back to 6.0.5 version no error appears.
From https://dev.mysql.com/doc/connector-j/6.0/en/connector-j-api-changes.html :
The name of the class that implements java.sql.Driver in MySQL Connector/J has changed from com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver. The old class name has been deprecated.
So I presume you updated the Driver classname to the cj package when you upgraded to 6.0.5, but you should change it back to com.mysql.jdbc.Driver make things work with 5.1.38.

Adding quartz to project breaks jdbc dataSource

I've already found out what was the problem, but decided to post it here, in case anyone else is banging head against the same wall.
I've added the latest version of quartz scheduler to my project:
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
And suddenly tests started falling with:
org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [ my sql ]; SQL state [null]; error code [0]; An SQLException was provoked by the following failure: java.lang.InterruptedException; nested exception is java.sql.SQLException: An SQLException was provoked by the following failure: java.lang.InterruptedException
Even more weird, when I've moved quartz dependency to another module, they started to fail with different exception:
Could not get JDBC Connection; nested exception is java.sql.SQLException: com.mchange.v2.c3p0.ComboPooledDataSource[ identityToken -> z8kfsx9b1qeyobp10iytmq|796c39ad, dataSourceName -> z8kfsx9b1qeyobp10iytmq|796c39ad ] has been closed() -- you can no longer use it.
So, Spring closed my ComboPooledDataSource, but why?
Removing quartz or changing it's version to 1.8.x helps. Exceptions happen even without instantiating any quartz object.
Quartz uses c3p0 jdbc pool for it's distributed job storage since version 2.x, and my project uses c3p0 too, but the newer 0.9.5 version, while the quartz uses 0.9.1.1. These versions are fairly different, the old one from quartz came first in my classpath, causing runtime exceptions. Since I don't use quartz distributed job storage, I've solved the problem by excluding transitive c3p0 dependency:
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
<!-- old c3p0 (0.9.1.1) in class path causes destruction of ComboPooledDataSource-->
<exclusions>
<exclusion>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
</exclusion>
</exclusions>
</dependency>

Categories