我 97% 确信我已经正确设置了 java web 应用程序,但我仍然收到错误,指出缺少 Mariadb 连接器或类似的东西。我已经尝试修复它但无济于事...我已经
- 在
pom.xml
文件中添加了 mariadb 的依赖关系(如第一张图片所示) - 检查
.jar
文件是否存在。 (如第一张图片所示) - 尝试清理和重建...
在运行时检查 GlashFish Server 选项卡后,我可以读到以下内容:
java.lang.ClassNotFoundException : com.mariadb.jdbc.Driver
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1580)
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1430)
... and at least 20 more locations.
<小时/>
在这里,我尝试在控制台中打印结果,以查看我的应用程序是否设法连接到远程数据库服务器,但我什么也没得到,因为它似乎在 行之前崩溃了Class.forName("com.mariadb.jdbc.Driver");
我发现这是 mariadb jdbc 在其 website 上的正确语法。为了节省您的时间,他们说这是执行此操作的传统方式,但它仍然有效。我确实尝试将 url 连接中的所有参数删除为仅 getConnection();
行中的用户和密码,但仍然失败。我错过了什么吗?
为了避免屏幕截图中出现混淆,myddns.link 包含 :3306,因此这不是错误。
最佳答案
应该是
Class.forName("org.mariadb.jdbc.Driver");
而不是
Class.forName("com.mariadb.jdbc.Driver");
documentation您链接甚至明确指出:
Please note that the driver class provided by MariaDB Connector/J is not com.mysql.jdbc.Driver but org.mariadb.jdbc.Driver!
关于java - 无法使用 Java 和 Mariadb 连接到远程数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59433560/