how to install mysqlconnecter java correctly?

2019-05-25 08:57发布

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:

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:

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?

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-05-25 09:02

The JDBC driver does not need any "installation".

You should not set the system wide CLASSPATH environment variable, that only leads to confusion.

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

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.

查看更多
Evening l夕情丶
3楼-- · 2019-05-25 09:06

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.

查看更多
登录 后发表回答