问题描述
浏览网页后,我意识到我应该在系统环境变量中将类路径设置为连接器jar文件的路径文件,并在命令行中输入此命令我有: C:\ Users \ User> echo%classpath%
D:\classpath\mysql-connector-java-5.1.22- bin.jar
但是当我写一个java程序来向我展示类路径时:
System.out.println(System.getProperty(java.class.path));
它告诉我这一个:
C:\Users\User\Documents\NetBeansProjects\JavaApplication3\build\classes; C:\Users\User\Documents\NetBeansProjects\JavaApplication3 \ src
我想连接数据库应该如何安装连接器?
JDBC驱动程序不需要任何安装。
你应该不设置系统范围 CLASSPATH
环境变量,这只会导致混淆。
启动程序时,只需将文件的位置提供给Java命令:
java -cp myapp.jar; D:\classpath \mysql-connector-java-5.1.22-bin.jar MyMain
要在NetBeans项目中使用它,请在项目的库部分中添加jar文件。
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?
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.
这篇关于如何正确安装mysqlconnecter java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!