How to set jdbc driver classpath

前端 未结 2 683
悲哀的现实
悲哀的现实 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: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

提交回复
热议问题