How to set jdbc driver classpath

前端 未结 2 682
悲哀的现实
悲哀的现实 2021-01-26 02:36

When I copy mysql jdbc driver to JDK\'s\\jre\\lib\\ext, it execute perfectly well. Now, I want to use the jdbc by specifying its classpath to environment variable. But, after d

相关标签:
2条回答
  • 2021-01-26 03:16

    You should not be putting ANY JARs in the jre/lib/ext folder.

    You set the CLASSPATH using the -classpath option on javac.exe when you compile and java.exe when you run. Make sure that your code and all 3rd party JARs are in the CLASSPATH when you compile and run. Windows uses the semi-colon as the separator; Linux uses colon.

    Maybe you need to start here:

    http://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html

    0 讨论(0)
  • 2021-01-26 03:36

    You can include any jar files you need by specifying them in the java command with the -cp switch (which is identical to -classpath. For example if the JDBC driver's name is 'myjdbc.jar' then you would execute your program as follows:

    java -cp myjdbc.jar your.package.YourClass

    If you have more jar files, you can separate them with a semi-colon on Windows or colon on Linux/Unix. Commonly the current directly is also included, and we put all needed jar files in a /lib folder, so it would look something like this (on Windows):

    java -cp .;lib/myjdbc.jar your.package.YourClass

    Also, if you have lots of jar files, it would be more convenient to put them all in the /lib folder and have something like this:

    java -cp .;lib/* your.package.YourClass

    0 讨论(0)
提交回复
热议问题