java - Class.forName (“com.mysql.jdbc.Driver” ) 在 Raspberry Pi 上不起作用

标签 java mysql jdbc classnotfoundexception

这段代码:

        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/

相关文章:

php - 从 php 更新多行 Mysql

java - 如果应用程序是多语言的,定位元素的最佳方法是什么?

php - 为什么我的函数不返回返回值?

java - 使用 Gluon ShareService 共享多个文件(图片和 txt)

php - 如何根据多个表和值分隔来选择SQL结果

java - JDBC - NetBeans x MySQL

java - 使用 Spring JDBC API 批量执行存储过程

java - 将 JDBC ResultSet 迁移到 JPA List 对象

java - 使用数组和多种方法进行编码给我带来错误并且无法找出原因

Java同步对象?