Groovy java.sql.SQLException: No suitable driver found for jdbc:sqlserver:// - windows

I am quite new to groovy and am quite confused about the Groovy java.sql.SQLException that I'm getting.
Here is my code
// https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc
#Grapes(
#Grab(group='com.microsoft.sqlserver', module='mssql-jdbc', version='7.2.2.jre8')
)
import groovy.sql.*
def username = xxx, password = yyy
// Create connection to MSSQL with classic JDBC DriverManager.
def db = Sql.newInstance("jdbc:sqlserver://localhost:1433;database=tempdb;", username, password, 'com.microsoft.sqlserver.jdbc.SQLServerDriver')
The same SQL JDBC Connection string ("jdbc:sqlserver://localhost:1433;database=tempdb;", 'com.microsoft.sqlserver.jdbc.SQLServerDriver') works just fine for my other cases, like Java or JMeter, but not works with groovy. This is what I'm getting:
> groovy groovy-sql-test.groovy
Picked up _JAVA_OPTIONS: -Xms512M -Xmx1g
Caught: java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost:1433;database=tempdb;
java.sql.SQLException: No suitable driver found for jdbc:sqlserver://localhost:1433;database=tempdb;
at groovy-sql-0.run(groovy-sql-0.groovy:11)
This is running under Win10.
I've also tried
groovy -cp D:\path\to\my\jars groovy-sql-test.groovy
where within the D:\path\to\my\jars dir, I'm having both sqljdbc41.jar and mssql-jdbc-7.2.2.jre8.jar files.

You have to use #GrabConfig(systemClassLoader=true) to use the system
classloader and thus get the jdbc driver picked up.
From https://groovy-lang.org/databases.html#_connecting_using_grab
The #GrabConfig statement is necessary to make sure the system
classloader is used. This ensures that the driver classes and system
classes like java.sql.DriverManager are in the same classloader.

Related

java.Sql.SQLException, Cannot load class net.ucanaccess.jdbc.UcanaccessDriver

I tried to connect my MS Access Database in Mulesoft using Ucanaccess driver but it raises error Could not load class net.ucanaccess.jdbc.UcanaccessDriver. I have imported all the required JAR's and added the required dependencies in pom.xml also but still it gives same error. I have attached all nescessary details of the problem. Java version - 8, Ucanaccess driver version - 5.0.1 Any suggestion or guidance to proceed further would be helpful for me.
Error Stack Trace
org.mule.runtime.api.connection.ConnectionException: Could not obtain connection from data source
org.mule.runtime.api.connection.ConnectionException: Could not obtain connection from data source
Caused by: org.mule.extension.db.api.exception.connection.ConnectionCreationException: Could not obtain connection from data source
Caused by: java.sql.SQLException: Error trying to load driver: net.ucanaccess.jdbc.UcanaccessDriver : Cannot load class 'net.ucanaccess.jdbc.UcanaccessDriver': [
net.ucanaccess.jdbc.UcanaccessDriver,
Cannot load class 'net.ucanaccess.jdbc.UcanaccessDriver': [
Class 'net.ucanaccess.jdbc.UcanaccessDriver' has no package mapping for region 'domain/default/app/tooling-application-85e45b90-5bac-11eb-84c6-ccd9aca566c1'.,
Cannot load class 'net.ucanaccess.jdbc.UcanaccessDriver': [
Class 'net.ucanaccess.jdbc.UcanaccessDriver' has no package mapping for region '/domain/default'.
Database Config
Pom.xml Dependencies
External Jar
Looks like you need to add the JDBC driver libraries as shared libraries in the pom.xml.
See the documentation at https://docs.mulesoft.com/mule-runtime/4.3/mmp-concept#configure-shared-libraries on how to configure.
Example (you might need to add other libraries):
<sharedLibraries>
<sharedLibrary>
<groupId>net.sf.ucanaccess</groupId>
<artifactId>ucanaccess</artifactId>
</sharedLibrary>
</sharedLibraries>

Connect to Teradata Using Airflow JDBC Connection

I'm trying to execute a SqlSensor task in Airflow using a connection to Teradata database. The connection is configured as follow:
I have provide in particular 2 driver paths separated by ", " but I am not sure if it's the proper way to do it?
/home/airflow/java_sample/tdgssconfig.jar
/home/airflow/java_sample/terajdbc4.jar
When the DAG executes, it triggers the error message
[2017-08-02 02:32:45,162] {models.py:1342} INFO - Executing <Task(SqlSensor): check_running_batch> on 2017-08-02 02:32:12
[2017-08-02 02:32:45,179] {base_hook.py:67} INFO - Using connection to: jdbc:teradata://myservername.mycompanyname.org/database=MYDBNAME,TMODE=ANSI,CHARSET=UTF8
[2017-08-02 02:32:45,313] {sensors.py:109} INFO - Poking: SELECT BATCH_KEY FROM MYDBNAME.AUDIT_BATCH WHERE BATCH_OWNER='ARO_TEST' AND AUDIT_STATUS_KEY=1;
[2017-08-02 02:32:45,316] {base_hook.py:67} INFO - Using connection to: jdbc:teradata://myservername.mycompanyname.org/database=MYDBNAME,TMODE=ANSI,CHARSET=UTF8
[2017-08-02 02:32:45,497] {models.py:1417} ERROR - java.lang.RuntimeException: Class com.teradata.jdbc.TeraDriver not found
What am I doing wrong?
The appropriate way to input multiple jars in the connections page is to separate both fully qualified paths with a comma which you did above.
I can confirm this is the approach I took and it worked (Airflow 10.1.1 and 10.1.2).
See: https://github.com/apache/airflow/blob/master/airflow/hooks/jdbc_hook.py#L51
Bonus: If you use Ad Hoc Query in Data Profiling to test it out, you'll notice that you'll get an error when you send a SELECT statement because Airflow wraps it in a LIMIT clause which TD doesn't support.
The solution provided by my team member was to merge the two jar into a single jar file. After doing it and indicating that new jar file in the driver path, it worked as expected.
Here is the link to the JAR file: https://github.com/alexisrolland/linux-setup/blob/master/teradataDriverJdbc.jar
Here is a code snippet example to use the connection in a SQLSensor Task:
CheckRunningBatch = SqlSensor(
task_id='check_running_batch',
conn_id='ed_data_quality_edw_dev',
sql="SELECT CASE WHEN MAX(BATCH_KEY) IS NOT NULL THEN 0 ELSE 1 END FROM DATABASE.AUDIT_BATCH WHERE STATUS_KEY=1;",
poke_interval=300,
dag=dag)

OrientDB 2.2.3 in OSGI environment

I have a pretty small OSGI application running in Apache Karaf, and it work fine on OrientDB version 2.1.11. But I've faced with following error when tried to start it on new 2.2.3 version:
Caused by: com.orientechnologies.orient.core.exception.ODatabaseException: Error on opening database 'remote:/localhost/testdb'
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.<init>(ODatabaseDocumentTx.java:187)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool$DatabaseDocumentTxPolled.<init>(OPartitionedDatabasePool.java:118)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool$DatabaseDocumentTxPolled.<init>(OPartitionedDatabasePool.java:114)
at com.orientechnologies.orient.core.db.OPartitionedDatabasePool.initQueue(OPartitionedDatabasePool.java:442)
This error occures on application install time when it's trying to initialise DB connection pool. After some debugging I found that the root problem is in method registerEngines() of class com.orientechnologies.orient.core.Orient where OrientDB classloader tries to find all implmentations of OEngine interface:
Iterator<OEngine> engines = OClassLoaderHelper.lookupProviderWithOrientClassLoader(OEngine.class, classLoader);
This call returns only 2 implementations, plocal and memory (located in the same bundle as registerEngines() - orientdb-core). The remote engine (com.orientechnologies.orient.client.remote.OEngineRemote) is located in orientdb-client bundle and OrientDB classloader can't find it.
Here is code fragment that creates DB connection poll and produces described error:
log.info("Creating OrientDB connection pool");
OGlobalConfiguration.NETWORK_BINARY_DNS_LOADBALANCING_ENABLED.setValue(true);
OPartitionedDatabasePool connectionPool = new OPartitionedDatabasePool(url, user, password);
log.info(String.format("Created OrientDB connection pool: url=%s", url));

DriverManager tries to use mariadb driver when connecting to h2 database

I'm doing some testing and got the following exception:
java.lang.IllegalArgumentException: Invalid connection URL url dbc:h2:db/test
at org.mariadb.jdbc.JDBCUrl.parse(JDBCUrl.java:144)
at org.mariadb.jdbc.Driver.connect(Driver.java:95)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
The code I'm using:
Class.forName("org.h2.Driver"); //load h2 driver
String connectionUrl = "jdbc:h2:db/test";
Connection conn = DriverManager.getConnection(connectionUrl, "sa", "");
I also test something related to mariadb/mysql, so the mariadb driver is also on classpath in addition to the h2 driver (eclipse project). If I remove the mariadb driver from classpath the connection works.
To my knowledge it should be possible to have multiple jdbc drivers on classpath or have I understood something wrong?
(h2 is version 1.3.176 and mariadb-java-client is 1.2.0)
EDIT: Using mariadb-java-client 1.2.2 removes the problem
I can confirm that this was a bug in the mariadb-jdbc-driver
https://mariadb.atlassian.net/plugins/servlet/mobile#issue/CONJ-167
I would assume this was some kind of bug, since I have not seen the problem after updating to mariadb-java-client 1.2.2 .

How to connect Hive in iReport?

I am using Hadoop-0.20.0 and Hive-0.8.0. Now i have data into Hive table and i want generate reports from that. For that I am using iReport-4.5.0. For that I also download HivePlugin-0.5.nbm in iReport.
Now I am going to connect Hive connection in iReport.
Create New Data source --> New --> Hive Connection
Jdbc Drive: org.apache.hadoop.hive.jdbc.HiveDriver
Jdbc URl: jdbc:hive//localhost:10000/default
Server Address: localhost
Database: default
user name: root
password: somepassword
Then click on Test connection button.
I am getting error like:
Exception
Message:
java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: java.lang.RuntimeException: Illegal Hadoop Version: Unknown (expected A.B.* format)
Level:
SEVERE
Stack Trace:
org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException:
java.lang.RuntimeException: Illegal Hadoop Version: Unknown (expected A.B.* format)
org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:226)
org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:72)
org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:110)
com.jaspersoft.ireport.designer.connection.JDBCConnection.getConnection(JDBCConnection.java:140)
com.jaspersoft.ireport.hadoop.hive.connection.HiveConnection.getConnection(HiveConnection.java:48)
com.jaspersoft.ireport.designer.connection.JDBCConnection.test(JDBCConnection.java:447)
com.jaspersoft.ireport.designer.connection.gui.ConnectionDialog.jButtonTestActionPerformed(ConnectionDialog.java:335)
com.jaspersoft.ireport.designer.connection.gui.ConnectionDialog.access$300(ConnectionDialog.java:43)
Can any one help me in this? Where i am wrong or missing something?
"I also download HivePlugin-0.5.nbm in iReport."
This isn't clear. iReport 4.5 has the Hadoop Hive connector pre-installed. Why did you download the connector separately? Did you install this plugin?
Create New Data source --> New --> Hive Connection
Jdbc Drive: org.apache.hadoop.hive.jdbc.HiveDriver
...
This isn't possible with the current Hadoop Hive connector. When you create a new "Hadoop Hive Connection" you are given only one parameter to fill out: the url.
I'm guessing that you created a JDBC connection when you meant to create a Hadoop Hive connection. This is a logical thing to do. Hive is accessed via JDBC. But the Hive JDBC driver is still pretty new. It has a number of shortcomings. That's why the Hive connector was added to iReport. It is based on the Hive JDBC driver, but it includes a wrapper around it to avoid some problems.
Or maybe you installed an old Hive connector over the top of the one that's already included with iReport 4.5. At some point in the past the Hive connector let you fill in extra information like the JDBC Driver.
Start with a fresh iReport installation, and make sure you use the Hadoop Hive Connection. That should clear it up.
The error "java.lang.RuntimeException: Illegal Hadoop Version: Unknown (expected A.B.* format)" happens because the VersionInfo class in hadoop-common.jar attempts to locate the version info using the current thread's class loader.
https://github.com/apache/hadoop/blob/release-2.6.0/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/VersionInfo.java#L41-L58
The code in question looks like this...
package org.apache.hadoop.util;
...
public class VersionInfo {
...
protected VersionInfo(String component) {
info = new Properties();
String versionInfoFile = component + "-version-info.properties";
InputStream is = null;
try {
is = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(versionInfoFile);
if (is == null) {
throw new IOException("Resource not found");
}
info.load(is);
} catch (IOException ex) {
LogFactory.getLog(getClass()).warn("Could not read '" +
versionInfoFile + "', " + ex.toString(), ex);
} finally {
IOUtils.closeStream(is);
}
}
If your tool attempts to connect to the datasource in a separate thread, it will generate this error.
The easiest way to work around the issue is to put the hadoop-common.jar library in $JAVA_HOME/lib/ext or use the command line setting -Djava.endorsed.dirs to point to the hadoop-common.jar library. Then the thread's class loader will always be able to find this information.

Resources