Clickhouse JDBC driver class name - java

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!

Related

WebDriverManager throwing TypeNotPresentException

I am trying to replace my local geckodriver.exe with WebDriverManager, but when i invoke
WebDriverManager.firefoxdriver().setup();
i get the following error
4391 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://api.github.com/repos/mozilla/geckodriver/releases to seek geckodriver
4704 [main] WARN io.github.bonigarcia.wdm.WebDriverManager - There was an error managing geckodriver (latest version) (Type com.google.gson.internal.LinkedTreeMap not present) ... trying again using latest driver stored in cache
4704 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Reading https://api.github.com/repos/mozilla/geckodriver/releases to seek geckodriver
4876 [main] ERROR io.github.bonigarcia.wdm.WebDriverManager - There was an error managing geckodriver (latest version) (Type com.google.gson.internal.LinkedTreeMap not present)
java.lang.TypeNotPresentException: Type com.google.gson.internal.LinkedTreeMap not present
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
...
at io.github.bonigarcia.wdm.WebDriverManager.fallback(WebDriverManager.java:825)
at io.github.bonigarcia.wdm.WebDriverManager.handleException(WebDriverManager.java:802)
at io.github.bonigarcia.wdm.WebDriverManager.manage(WebDriverManager.java:599)
at io.github.bonigarcia.wdm.WebDriverManager.setup(WebDriverManager.java:287)
I am using the latest 5.0.3 WebDriverManager from maven
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
</dependency>
TypeNotPresentException is thrown when an application tries to access a type using a string representing the type's name, but no definition for the type with the specified name can be found.
It's pretty similar to ClassNotFoundException, but not checked during compilation.
But the root cause is:
com.google.gson.internal.LinkedTreeMap not present in the project classpath.
Try to add gson dependency to the project.
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency>
https://docs.oracle.com/javase/9/docs/api/java/lang/TypeNotPresentException.html
Change the WebDriverManager scope to test in pom.xml as follows:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
<scope>test</scope>
</dependency>
or change the scope to compile in pom.xml as follows:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.0.3</version>
<scope>compile</scope>
</dependency>
Additionally, you may need to add the slf4j dependency as follows:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
As per Driver Management - Feature:
Although not mandatory, it is highly recommended to use a logger library to trace your application and tests. In the case of WebDriverManager, you will see the relevant steps of the driver management following its traces. See for example the following tutorial to use SLF4J and Logback. Also, you can see an example of a WebDriverManager test using logging here (this example uses this configuration file).
Reference
You can find a couple of relevant detailed discussion in:
I am getting an error while executing the basic website launch using web driver manager

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.

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.

Camel catching jdbc exception ClassNotFound running on karaf

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.

Maven dependencies in a Mule project . Classloader control not working as expected

I'm trying to build a mule project in maven which uses a library that in turn uses apache-commons-codec-1.8 . Mule 3.5 currently supports only v 1.3
In order to get around this Ive implemented classloader control in mule and blocked mule from loading its version of the library by doing the following in mule-deploy.properties.
loader.override=-org.apache.commons.codec
In addition I've updated my pom.xml to include the 1.9 version of the library . Here is a snapshot of running mvn:dependency tree on the project.
However, when I run my test method I get a runtime exception
java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString([B)Ljava/lang/String;
at com.nimbusds.jose.util.Base64URL.encode(Base64URL.java:64)
at com.nimbusds.jose.util.Base64URL.encode(Base64URL.java:91)
at com.nimbusds.jose.Header.toBase64URL(Header.java:238)
at com.nimbusds.jose.JWSObject.<init>(JWSObject.java:101)
at com.package.components.lastmile.originator.TokenSignerTemplate.sign(TokenSignerTemplate.java:109)
at com.package.components.lastmile.originator.TokenSignerTemplate.signClaim(TokenSignerTemplate.java:122)
at com.package.orchestration.LMSFakeClaimsHandler.testSignParse_Positive(LMSFakeClaimsHandler.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
which is clearly because it's referencing the older version of apache-commons. How do I make sure that it references only the latest version and not the older version?
mule-deploy.properties
#Fri Dec 12 09:58:12 PST 2014
loader.override=-org.apache.commons.codec
redeployment.enabled=true
encoding=UTF-8
domain=default
config.resources=..flows.
.
Relevant positions of pom.xml
<dependencies>
....
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
....
<!-- Test to check commons-codec works -->
<dependency>
<groupId>org.mule.transports</groupId>
<artifactId>mule-transport-http</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
P.S: The same snippet seems to work fine on a non mule project, indicating this is a mule related issue.
If you are running the Mule app in Mule server, excluding the lib from the pom will not work, since the codec lib is present in the server itself.
Try to insert the newest codec lib version in the server lib shared folder (maintaining the property loader.override=-org.apache.commons.codec)
Add the following exclusion to your pom.
<dependency>
<groupId>org.mule.transports</groupId>
<artifactId>mule-transport-http</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
And then add the dependency of Commons Codec 1.9.
Then your override property in mule-deploy.properties will work as expected.
Update: 12/30:
The override property seems to be the problem.
loader.override=-org.apache.commons.codec is not correct.
Try the following
loader.override=org.apache.commons.codec
Hope this helps.
I have a similar issue with the jackson-xc. I don't know why Mule 3.5 comes with a mix of jackson 1 and 2 libraries
jackson-annotations-2.1.1.jar
jackson-core-2.1.1.jar
jackson-databind-2.1.1.jar
jackson-core-asl-1.9.11.jar
jackson-jaxrs-1.9.11.jar
jackson-mapper-asl-1.9.11.jar
jackson-xc-1.7.1.jar
And with jackson-xc-1.7.1 instead of jackson-xc-1.9.11 that would be aligned to the version of the other jackson 1 libraries.
In my application it is producing the "classic" library issue exception:
Caused by: java.lang.AbstractMethodError
at org.codehaus.jackson.map.AnnotationIntrospector$Pair.findDeserializer(AnnotationIntrospector.java:1335)
Since using
loader.override=...
into the mule-deploy.properties didn't work (with either override and/or blocking on the package org.codehaus.jackson.xc and on the class org.codehaus.jackson.xc.JaxbAnnotationIntrospector) the only solution I have found goes in the direction of Nuno's answer and is to put the jar we want to use in a lib folder with higher priority than lib/opt
lib/shared has been deprecated but you can use lib/user to override.
I would prefer to use the loader.override (classloader-control-in-mule 3.5) and avoid the modification of all the installation, but for now is the only solution that is working for me.

Categories