Where do I install a jdbc driver on ubuntu?
Asked Answered
T

4

8

I'm trying to install the MS SQL JDBC driver on ubuntu to be used with sqoop for Hadoop. I'm totally new to java and linux, so I'm not sure where to extract everything to.

Therapist answered 15/3, 2011 at 3:0 Comment(0)
K
7

Just put it in the runtime classpath or add its path to the runtime classpath.

How to do it depends on how you're executing the program. If you're using java command in command console to execute a .class file, then use the -cp argument to specify the paths to classes and/or JAR files which are to be taken in the classpath. The classpath is basically a collection of absolute/relative disk file system paths where Java has to look for JAR files and classes.

Assuming that you've downloaded a .zip, you need to extract it and then look for a .jar file (usually in a /lib folder). For starters, it's the easiest to put the .jar in the current working directory and then execute your program (with the Class.forName("com.mysql.jdbc.Driver"); line) as follows:

java -cp .:mysql.jar com.example.YourClass

The . signifies the current path and the : is the separator (which I believe is correct for Ubuntu, on Windows it's ;).

Kidding answered 15/3, 2011 at 3:2 Comment(2)
+1, nice answer, BTW in your examples you use mysql, while question is about MS SQLWymore
Yeah it's good, but for running on a hadoop cluster, you'll need to set the jar in the job configuration's "libjar". Maybe you can extend your answer :)Donata
U
3

To install the driver, you can:

  1. Download the driver from Microsoft: https://www.microsoft.com/en-us/download/details.aspx?id=11774
  2. Unzip and untar it (gzip -d sqljdbc_6.0.7507.100_enu.tar.gz and tar -xf sqljdbc_6.0.7507.100_enu.tar)

  3. Install it by copying the correct version into /usr/share/java (It will need to be world readable.) (sudo cp sqljdbc42.jar /usr/share/java/)

  4. In the tomcat directory (/usr/share/tomcat8/lib but it could be tomcat7 if you are running a different version.) run sudo ln -s ../../java/sqljdbc42.jar sqljdbc42.jar (with the correct version names from below).
  5. If you are using Maven, see Setting up maven dependency for SQL Server

The correct version is as follows: (Under System Requirements)

  • Sqljdbc.jar requires a JRE of 5 and supports the JDBC 3.0 API
  • Sqljdbc4.jar requires a JRE of 6 and supports the JDBC 4.0 API
  • Sqljdbc41.jar requires a JRE of 7 and supports the JDBC 4.1 API
  • Sqljdbc42.jar requires a JRE of 8 and supports the JDBC 4.2 API
Unloosen answered 3/8, 2016 at 18:46 Comment(0)
V
1

Just put your jdbc jar file into /usr/lib/jvm/java-8-oracle/jre/lib/ext by using this command:

sudo cp ojdbc6.jar /usr/lib/jvm/java-8-oracle/jre/lib/ext

Valles answered 11/9, 2019 at 5:36 Comment(0)
K
0

1. Downloaded the JDBC driver

Download the driver from Mysql here

1.1. Ubuntu and Debian Linux distributions

You can download the .deb file, and run

sudo apt update
sudo apt install ./mysql-connector-j-9.0.0.tar.gz

This command will copy the .jar file into the /usr/share/java/mysql-connector-j-9.0.0.jar <-- save this path for later

If you don't find the file there, you can run whereis java and search for this file in each of the directories this command outputs.

1.2. Windows, any other OS

You can select the Platform Independent option and download the zip file.

Save the zip file path for later

NOTE: If you delete this file later, you won't have the driver anymore

2. Associate to the Classpath in IDE

2.1. VSCode

  1. Install the extension Extension Pack for Java installed on VSCode
  2. Open the command palette (Ctrl+Shift+P)
  3. Search for "Java: Configure Classpath"
  4. Open Libraries tab
  5. Press on + Add Library button
  6. Select the .jar or file (in the path you saved before, e.g.:/usr/share/java/mysql-connector-j-9.0.0.jar` or where you downloaded the ZIP file)

After this, the JDBC driver should be linked to your project classpath.

2.2. IntelliJ

  1. Open menu File > Project Structure
  2. Libraries tab
  3. Press the "+" button
  4. Select Java
  5. Select the .jar or .zip file (in the path you saved before, e.g.: /usr/share/java/mysql-connector-j-9.0.0.jar or where you downloaded the ZIP file)

Hope that helps!

Kristy answered 5/9, 2024 at 14:41 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.