Ich machte eine einfache Java EE-App, und ich habe ein Problem mit der Verbindung zur Datenbank. In Eclipse funktioniert alles gut, aber wenn ich das gleiche versuche, treten intellij Fehler auf.java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource in IntelliJ, während es in Eclipse funktioniert
package db;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;
public class DbUtil {
private static DbUtil dbUtil;
private ComboPooledDataSource connectionPool;
private DbUtil() throws PropertyVetoException {
connectionPool = new ComboPooledDataSource();
connectionPool.setDriverClass("com.mysql.jdbc.Driver");
connectionPool.setJdbcUrl("jdbc:mysql://localhost:3306/world");
connectionPool.setUser("root");
connectionPool.setPassword("root");
connectionPool.setInitialPoolSize(5);
connectionPool.setMinPoolSize(5);
connectionPool.setMaxPoolSize(20);
connectionPool.setAcquireIncrement(5);
connectionPool.setMaxIdleTime(3600);
}
public Connection getConnection() throws SQLException {
return connectionPool.getConnection();
}
public void close() {
connectionPool.close();
}
public static DbUtil getInstance() {
if (dbUtil == null) {
try {
dbUtil = new DbUtil();
} catch (PropertyVetoException e) {
e.printStackTrace();
}
}
return dbUtil;
}
}
In Projektstruktur -> Bibliotheken Ich habe: image
Und die Fehler sind:
java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/ComboPooledDataSource
java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource
, wenn diese „Bibliotheken“ repräsentieren JAR-Dateien in dem Bild, zumindest müssen Sie auch das Glas für mchange-commons-Java-Version 0.2.11 oder höher pom Abhängigkeiten . –