如何正确安装mysqlconnecter java?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12601879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 09:30:59  来源:igfitidea点击:

how to install mysqlconnecter java correctly?

javamysqlnetbeansconnector

提问by Nickool

after surfing the web I realized that I should set the class path the path File of the connecter jar file in system environment variables I did so and in commandline by entering this command I have this:

在网上冲浪后,我意识到我应该在系统环境变量中设置类路径连接器 jar 文件的路径文件我这样做了,在命令行中输入这个命令我有这个:

C:\Users\User>echo %classpath%
D:\classpath\mysql-connector-java-5.1.22-bin.jar

but when I wrote a java program to show me the class path:

但是当我写了一个java程序来显示类路径时:

System.out.println(System.getProperty("java.class.path"));

it shows me this one:

它向我展示了这个:

C:\Users\User\Documents\NetBeansProjects\JavaApplication3\build\classes;C:\Users\User\Documents\NetBeansProjects\JavaApplication3\src

I want to connect to a database how should I install my connector?

我想连接到数据库我应该如何安装我的连接器?

回答by a_horse_with_no_name

The JDBC driver does not need any "installation".

JDBC 驱动程序不需要任何“安装”。

You should notset the system wide CLASSPATHenvironment variable, that only leads to confusion.

你应该设置全系统CLASSPATH的环境变量,只能导致混乱。

When starting your program, simply provide the location of the file to the Java command:

启动程序时,只需将文件的位置提供给 Java 命令:

java -cp myapp.jar;D:\classpath\mysql-connector-java-5.1.22-bin.jar MyMain

To use it inside your NetBeans project, add the jar file in the "Libraries" section of your project.

要在 NetBeans 项目中使用它,请将 jar 文件添加到项目的“库”部分。

回答by Dhanush Gopinath

Just add *D:\classpath*to the CLASSPTH using set command (set CLASSPATH=%CLASSPATH%;D:\classpath;) on the command prompt or by defining a CLASSPATH environment variable using UI.

只需在命令提示符下使用 set 命令 ( ) 或通过使用 UI 定义 CLASSPATH 环境变量将 * D:\classpath*添加到 CLASSPTH set CLASSPATH=%CLASSPATH%;D:\classpath;