运行GeneratorDemo类自动生成PostgreSql持久化类时出现异常

我用的包和数据源都是PostgreSql的:

jdbcUrl = jdbc:postgresql://47.95.248.0:5432/datagod?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull

方言也设置的是:gernerator.setDialect(new PostgreSqlDialect());

为何这里会报Could not load driverClass com.mysql.jdbc.Driver?

[WARN]-[Thread: com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1]-[com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded()]: Could not load driverClass com.mysql.jdbc.Driver

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

at java.net.URLClassLoader$1.run(URLClassLoader.java:366)

at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

at java.lang.ClassLoader.loadClass(ClassLoader.java:425)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:191)

at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)

at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)

at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)

at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)

at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)

at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)

at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)

at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)


评论区

JFinal

2018-04-13 09:54

异常提示缺少 jdbc 的 jar 包:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

libofei

2018-04-13 09:56

@JFinal 但提示的是mysql的jar包啊,可实际我需要用的是Postgresql

JFinal

2018-04-13 10:23

@libofei driverClass 要设置一下:
DruidPlugin dp = new DruidPlugin(……);
me.add(dp);
//配置Oracle驱动
dp.setDriverClass("oracle.jdbc.driver.OracleDriver");

注意上面代码中的 driverClass 是 oracle 的,你得改成 PostgreSql 的,上面的仅为示例

参考 oracle 的作法,举一反三用于 postgresql 上:
http://www.jfinal.com/doc/5-12

libofei

2018-04-13 11:11

@JFinal 好的,我研究一下

热门反馈

扫码入社