这段代码:
Class.forName("com.mysql.jdbc.Driver");
导致
ClassNotFoundException
在树莓派上。虽然我的类路径是正确的
pi@raspberrypi ~ $ echo $CLASSPATH
/usr/share/java/mysql-connector-java.jar
在 Windows 上它工作正常! 知道我做错了什么吗?
我还尝试用
开始我的应用程序java -cp /usr/share/java/mysql-connector-java.jar -jar myApp.jar
谢谢 弗洛里安
最佳答案
您正在使用 -jar
,这使得 -cp
部分无关紧要。来自documentation :
When you use the -jar option, the specified JAR file is the source of all user classes, and other class path settings are ignored.
或者add ClassPath entries in your jar manifest ,或将 MySQL 连接器 jar 文件添加到扩展目录(例如 jre/lib/ext
)。不过,使用 list 是最干净的方法。
关于java - Class.forName (“com.mysql.jdbc.Driver” ) 在 Raspberry Pi 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22689012/