gpt4 book ai didi

jakarta-ee - IntelliJ 中的 java.lang.ClassNotFoundException : com. mchange.v2.c3p0.ComboPooledDataSource 而在 Eclipse 中工作正常

转载 作者:行者123 更新时间:2023-12-02 07:07:30 24 4
gpt4 key购买 nike

我制作了一个简单的 Java EE 应用程序,但在连接数据库时遇到问题。在 Eclipse 中,一切工作正常,但是当我在 Intellij 中尝试相同的操作时,就会出现错误。

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;
}
}

在项目结构->库中我有: image

错误是:

java.lang.NoClassDefFoundError: com/mchange/v2/c3p0/ComboPooledDataSource
java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource

最佳答案

已经很长时间了,但我遇到了同样的问题,并且这个解决方案有效。

project_name/web/WEB-INF/创建名为 lib 的新文件夹,复制 .jars c3p0-0.9.5.2、c3p0-oracle-thin-extras-0.9.5.2、mchange-commons-java-0.2.11然后在项目 View 中选择 lib 文件夹,最后添加为库...

关于jakarta-ee - IntelliJ 中的 java.lang.ClassNotFoundException : com. mchange.v2.c3p0.ComboPooledDataSource 而在 Eclipse 中工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38036607/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com