Where do I install a jdbc driver on ubuntu?
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 ;
).
To install the driver, you can:
- Download the driver from Microsoft: https://www.microsoft.com/en-us/download/details.aspx?id=11774
Unzip and untar it (
gzip -d sqljdbc_6.0.7507.100_enu.tar.gz
andtar -xf sqljdbc_6.0.7507.100_enu.tar
)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/
)- In the tomcat directory (
/usr/share/tomcat8/lib
but it could be tomcat7 if you are running a different version.) runsudo ln -s ../../java/sqljdbc42.jar sqljdbc42.jar
(with the correct version names from below). - 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
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