By: Dallas Snider | Updated: 2016-09-14 | Comments (1) | Related: More > Big Data
Problem
I am receiving the following error when running Apache's Sqoop to connect to a SQL Server database:
java.lang.RuntimeException: Could not load db driver class: com.microsoft.sqlserver.jdbc.SQLServerDriver
How can I resolve this error?
Solution
Fortunately, this error message is very descriptive - the JDBC SQL Server driver cannot be loaded. The complete error message is shown below.
[hdfs@localhost ~]$ ./sqoopCommand.sh 16/08/16 20:41:36 INFO sqoop.Sqoop: Running Sqoop version: 1.4.5-cdh5.2.0 Enter password: 16/08/16 20:41:43 INFO manager.SqlManager: Using default fetchSize of 1000 16/08/16 20:41:43 INFO tool.CodeGenTool: Beginning code generation 16/08/16 20:41:43 ERROR sqoop.Sqoop: Got exception running Sqoop: java.lang.RuntimeException: Could not load db driver class: com.microsoft.sqlserver.jdbc.SQLServerDriver java.lang.RuntimeException: Could not load db driver class: com.microsoft.sqlserver.jdbc.SQLServerDriver at org.apache.sqoop.manager.SqlManager.makeConnection(SqlManager.java:848) at org.apache.sqoop.manager.GenericJdbcManager.getConnection(GenericJdbcManager.java:52) at org.apache.sqoop.manager.SqlManager.execute(SqlManager.java:736) at org.apache.sqoop.manager.SqlManager.execute(SqlManager.java:759) at org.apache.sqoop.manager.SqlManager.getColumnInfoForRawQuery(SqlManager.java:269) at org.apache.sqoop.manager.SqlManager.getColumnTypesForRawQuery(SqlManager.java:240) at org.apache.sqoop.manager.SqlManager.getColumnTypes(SqlManager.java:226) at org.apache.sqoop.manager.ConnManager.getColumnTypes(ConnManager.java:295) at org.apache.sqoop.orm.ClassWriter.getColumnTypes(ClassWriter.java:1829) at org.apache.sqoop.orm.ClassWriter.generate(ClassWriter.java:1641) at org.apache.sqoop.tool.CodeGenTool.generateORM(CodeGenTool.java:96) at org.apache.sqoop.tool.ImportTool.importTable(ImportTool.java:478) at org.apache.sqoop.tool.ImportTool.run(ImportTool.java:605) at org.apache.sqoop.Sqoop.run(Sqoop.java:143) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70) at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:179) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:218) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:227) at org.apache.sqoop.Sqoop.main(Sqoop.java:236) [hdfs@localhost ~]$
I have seen on two different Cloudera distributions of the Hadoop Distributed File System where the SQL Server driver was not installed by default. We have to download the correct driver from Microsoft and move it to the correct directory.
The SQL Server JDBC drivers are available from Microsoft at their Download Center website.
We will select version 4.2. On our Linux server, we will download a zipped tar file.
As of now, the file is named sqljdbc_4.2.6420.100_enu.tar.gz.
Next, we will unzip the tar file and extract the files in the tar file.
Notice there are several *.jar files. These are the driver files, but we are only interested in one of them, sqljdbc4.jar. Copy sqljdbc4.jar from the extracted directory to /usr/lib/sqoop/lib/.
Finally, we want to run our sqoop command again to make sure it works correctly.
If you use the wrong version, you will receive an error stating the wrong version as shown below.
[hdfs@localhost]$ ./sqoopCommand.sh 16/08/16 21:45:24 INFO sqoop.Sqoop: Running Sqoop version: 1.4.5-cdh5.2.0 Enter password: 16/08/16 21:45:27 INFO manager.SqlManager: Using default fetchSize of 1000 16/08/16 21:45:27 INFO tool.CodeGenTool: Beginning code generation Aug 16, 2016 9:45:27 PM com.microsoft.sqlserver.jdbc.SQLServerConnectionSEVERE: Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0. 16/08/16 21:45:27 ERROR sqoop.Sqoop: Got exception running Sqoop: java.lang.UnsupportedOperationException: Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0. java.lang.UnsupportedOperationException: Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0. at com.microsoft.sqlserver.jdbc.SQLServerConnection. (SQLServerConnection.java:304) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1011) at java.sql.DriverManager.getConnection(DriverManager.java:579) at java.sql.DriverManager.getConnection(DriverManager.java:221) at org.apache.sqoop.manager.SqlManager.makeConnection(SqlManager.java:877) at org.apache.sqoop.manager.GenericJdbcManager.getConnection(GenericJdbcManager.java:52) at org.apache.sqoop.manager.SqlManager.execute(SqlManager.java:736) at org.apache.sqoop.manager.SqlManager.execute(SqlManager.java:759) at org.apache.sqoop.manager.SqlManager.getColumnInfoForRawQuery(SqlManager.java:269) at org.apache.sqoop.manager.SqlManager.getColumnTypesForRawQuery(SqlManager.java:240) at org.apache.sqoop.manager.SqlManager.getColumnTypes(SqlManager.java:226) at org.apache.sqoop.manager.ConnManager.getColumnTypes(ConnManager.java:295) at org.apache.sqoop.orm.ClassWriter.getColumnTypes(ClassWriter.java:1829) at org.apache.sqoop.orm.ClassWriter.generate(ClassWriter.java:1641) at org.apache.sqoop.tool.CodeGenTool.generateORM(CodeGenTool.java:96) at org.apache.sqoop.tool.ImportTool.importTable(ImportTool.java:478) at org.apache.sqoop.tool.ImportTool.run(ImportTool.java:605) at org.apache.sqoop.Sqoop.run(Sqoop.java:143) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70) at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:179) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:218) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:227) at org.apache.sqoop.Sqoop.main(Sqoop.java:236) [hdfs@localhost]$
Next Steps
- Please experiment with loading different tables and views as shown in the previous tips on Sqoop.
- Finally, please check out these other tips and tutorials on T-SQL on MSSQLTips.com.
About the author
This author pledges the content of this article is based on professional experience and not AI generated.
View all my tips
Article Last Updated: 2016-09-14