如何设置jdbc驱动程序类路径 [英] How to set jdbc driver classpath

查看:298
本文介绍了如何设置jdbc驱动程序类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将mysql jdbc驱动程序复制到JDK的\ jre \lib \ ext时,它执行得非常好。现在,我想通过将其类路径指定为环境变量来使用jdbc。
但是,执行此操作后,我的程序抛出异常:

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 doing so, my program throws exception :


java.sql.SQLException:找不到合适的驱动程序
jdbc:mysql:// localhost / books

"java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/books"

如何设置类路径?

推荐答案

你不应该把任何JAR放在jre / lib / ext文件夹中。

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

你在编译时使用javac.exe上的-classpath选项设置CLASSPATH,并在运行时使用java.exe。编译和运行时,请确保您的代码和所有第三方JAR都在CLASSPATH中。 Windows使用分号作为分隔符; Linux使用冒号。

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

这篇关于如何设置jdbc驱动程序类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆