在 ubuntu 上哪里安装 jdbc 驱动程序?
我正在尝试在 ubuntu 上安装 MS SQL JDBC 驱动程序,以便与 sqoop for Hadoop 一起使用。我对 java 和 linux 完全陌生,所以我不确定将所有内容提取到哪里。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需将其放入运行时类路径中或将其路径添加到运行时类路径中即可。
如何执行取决于您如何执行程序。如果您在命令控制台中使用
java
命令来执行.class
文件,则使用-cp
参数指定类的路径和/或要在类路径中获取的 JAR 文件。类路径基本上是绝对/相对磁盘文件系统路径的集合,Java 必须在其中查找 JAR 文件和类。假设您已经下载了
.zip
,您需要将其解压,然后查找.jar
文件(通常位于/lib
文件夹)。对于初学者来说,最简单的方法是将.jar
放入当前工作目录,然后执行程序(使用Class.forName("com.mysql.jdbc.Driver");< /code> 行)如下:
.
表示当前路径,:
是分隔符(我相信这对于 Ubuntu 来说是正确的,在 Windows 上是; )。
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 theClass.forName("com.mysql.jdbc.Driver");
line) as follows:The
.
signifies the current path and the:
is the separator (which I believe is correct for Ubuntu, on Windows it's;
).要安装驱动程序,您可以:
解压缩并解压它 (
gzip -d sqljdbc_6.0.7507.100_enu.tar.gz
和tar -xf sqljdbc_6.0.7507.100_enu.tar
)通过将正确的版本复制到 /usr/share/java 来安装它(它需要是世界可读的。) (
sudo cp sqljdbc42.jar /usr/share/java/
)/usr/share/tomcat8/lib
但如果您运行的是不同版本,则可能是 tomcat7。)运行sudo ln -s ../../java/sqljdbc42.jar sqljdbc42.jar
(使用下面的正确版本名称)。正确的版本如下:(在系统要求下)
To install the driver, you can:
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/
)/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).The correct version is as follows: (Under System Requirements)
只需使用以下命令将 jdbc jar 文件放入
/usr/lib/jvm/java-8-oracle/jre/lib/ext
中:Just put your jdbc jar file into
/usr/lib/jvm/java-8-oracle/jre/lib/ext
by using this command:1.下载JDBC驱动程序
这里从Mysql下载驱动程序
1.1. Ubuntu 和 Debian Linux 发行版
您可以下载
.deb
文件,然后运行此命令会将
.jar
文件复制到/usr/share/java/mysql -connector-j-9.0.0.jar
<-- 保存此路径供以后使用如果在那里找不到该文件,可以运行
whereis java 并在此命令输出的每个目录中搜索该文件。
1.2. Windows、任何其他操作系统
您可以选择
平台无关
选项并下载 zip 文件。保存 zip 文件路径以供稍后使用
注意:如果稍后删除此文件,您将不再拥有驱动程序
中的类路径
2. 关联到 IDE 2.1 。 VSCode
Ctrl+Shift+P
).jar
或文件(在您之前保存的路径中,例如:
/usr/share/java/mysql-connector-j-9.0。 0.jar` 或您下载 ZIP 文件的位置)此后,JDBC 驱动程序应链接到您的项目类路径。
2.2. IntelliJ
.jar
或.zip
文件(在您之前保存的路径中,例如:/usr/ share/java/mysql-connector-j-9.0.0.jar
或您下载 ZIP 文件的位置)希望有帮助!
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 runThis command will copy the
.jar
file into the/usr/share/java/mysql-connector-j-9.0.0.jar
<-- save this path for laterIf 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
Ctrl+Shift+P
).jar
orfile (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
.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!