【发布时间】:2015-12-24 22:19:46
【问题描述】:
所以我按照其他帖子中列出的所有步骤将 mysql-connector-java-5.1.36-bin 添加到 intellij 12 中的类路径中,当我编写代码时,intellij 清楚地看到它并让我导入它,但是当我在 tomcat 中运行应用程序时,我得到一个 ClassNotFoundException
public void runLookUp(String s){
String url = "jdbc:mysql://localhost:3316/test";
String username = "java";
String password = "password";
System.out.println("Connecting database...");
System.out.println("Loading driver...");
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver loaded!");
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Cannot find the driver in the classpath!", e);
}
try {
Connection connection = (Connection) DriverManager.getConnection(url, username, password);
System.out.println("Database connected!");
} catch (SQLException e) {
throw new IllegalStateException("Cannot connect the database!", e);
}
}
我知道在全局库而不是我的 lib 目录中执行此操作是不好的形式,我最初在那里执行此操作并将其移至全局以尝试解决此问题,但尚未将其移回。鉴于这似乎适用于其他所有人,我认为这与我从 intellij 部署我的 tomcat 的方式一样,有什么想法吗?
【问题讨论】:
标签: java mysql tomcat intellij-idea classpath