【发布时间】:2018-03-15 12:52:48
【问题描述】:
我的 Liferay 门户 7 ga4 在 Wildfly 10 上运行。我创建了一个 Liferay MVC portlet 并进行了部署。我正在尝试连接到 MySql 数据库但收到此错误:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
我通过(右键单击项目>构建路径>配置构建路径>添加 JAR 导入 mysql-connector-java-5.1.42-bin.jar。它位于“引用的库”下。
这是 view.jsp 的代码
try{
String connectionURL = "jdbc:mysql://localhost/employees";
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "");
statement = connection.createStatement();
if(!connection.isClosed()){
out.println("Successfully connected to MySQL server" + "<br/>");
}
} catch(Exception ex){
out.println("Unable to connect to database: "+ ex);
}
有人可以帮帮我吗?我对 Liferay 和 Java 完全陌生。
谢谢。
【问题讨论】:
-
好像没有重复,这个问题好像和gradle config和OSGi环境有关。你能显示你的 gradle 配置吗?
标签: java osgi mysql-connector liferay-7