Learn more about SQL Server tools

mssqltips logo
giveaway
 

Tutorials          DBA          Dev          BI          Career          Categories          Webcasts          Whitepapers          Today's Tip          Join

Tutorials      DBA      Dev      BI      Categories      Webcasts

DBA    Dev    BI    Categories

 

Sqoop Runtime Exception: Cannot Load SQL Server Driver


By:   |   Read Comments (1)   |   Related Tips: More > Big Data


Free MSSQLTips Webcast Today >> Optimize SQL Server Performance


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.

Microsoft JDBC Drivers Download Center website

We will select version 4.2. On our Linux server, we will download a zipped tar file.

Select the correct version of the JDBC driver you want to download

As of now, the file is named sqljdbc_4.2.6420.100_enu.tar.gz.

Linux directory containing the compressed tar file.

Next, we will unzip the tar file and extract the files in the tar file.

Extracted files.

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/.

Copy the jar file to the sqoop lib directory.

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.SQLServerConnection 
SEVERE: 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


Last Update:


signup button

next tip button



About the author
MSSQLTips author Dallas Snider Dr. Dallas Snider is an Assistant Professor in the Computer Science Department at the University of West Florida and has 18+ years of SQL experience.

View all my tips
Related Resources





Post a comment or let the author know this tip helped.

All comments are reviewed, so stay on subject or we may delete your comment. Note: your email address is not published. Required fields are marked with an asterisk (*).

*Name    *Email    Notify for updates 


SQL tips:

*Enter Code refresh code     



Wednesday, May 17, 2017 - 5:43:52 PM - Eugene Back To Top

Hello Dallas, thank you for the solution. As it appeared, it was exactly what I was looking for.

I am running Sqoop version: 1.4.6-cdh5.7.1 and unfortunatelly cannot install missing sqljdbc4.2 file on sqoop server. I was proposed to install it on the sql server box instead and use --driver option in sqoop command. I dowloaded, unzipped it and it sits in \\server_name\c$\temp\Microsoft JDBC Driver 4.2 for SQL Server\sqljdbc_4.2

Sqoop command: sqoop export --connect jdbc:sqlserver://server_name/ --username user --password pwd --table A --hcatalog-table all_company --columns company_id --driver \server_name\c$\temp\Microsoft JDBC Driver 4.2 for SQL Server\sqljdbc_4.2

Could you please tell me if that is something you'd do and if so, what would be the correct sqoop command.

Thanks, 

Eugene


Learn more about SQL Server tools