Generator 代码生成器是不是不支持 sql server? , 运行总出错,无法自动生成代码。

Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: Connections could not be acquired from the underlying database!

at com.jfinal.plugin.activerecord.generator.MetaBuilder.build(MetaBuilder.java:102)

at com.jfinal.plugin.activerecord.generator.Generator.generate(Generator.java:210)

at com.demo.common.model._JFinalDemoGenerator.main(_JFinalDemoGenerator.java:45)

Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!

at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)

at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)

at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)

at com.jfinal.plugin.activerecord.generator.MetaBuilder.build(MetaBuilder.java:90)

... 2 more

Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.

at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)

at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)

at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)

at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)

... 4 more


评论区

JFinal

2016-12-08 11:43

错误提示已经很明确,无法获取连接:Connections could not be acquired from the underlying database!

这类错误无非就是如下几个原因:
1:连接数据库的用户名错误,密码错误
2:数据库名错误
3:连接用的用户账号没有权限

总之是配置的问题

gxlzlijng

2016-12-08 12:13

波总,真的不行, 我反复查过你说的那三个原因都没有错的,数据库连接和权限都没问题的,你看还有别的原因吗,还是 generator 没有测试过 sql server 环境。

JFinal

2016-12-08 12:58

@gxlzlijng 原因就是无法获取连接,要定位这个错误极其容易,先用纯 JDBC 配好参数去连一下,确定能连上以后,再将前面配置好 JDBC 参数 copy 到 jfinal 代码中来

JFinal

2016-12-08 12:59

@gxlzlijng 如果纯 JDBC 都连不上数据库,那就想办法直到能连上,下一步才是将配置转到 jfinal 配置之中

JFinal

2016-12-08 13:00

@gxlzlijng 连上数据库这是后续所有代码可以正常运行的前提,一定要先解决掉,用纯 jdbc 连上以后,还建议再用一下 jdbc 查询下数据,看能否成功

gxlzlijng

2016-12-08 16:25

波总您好,我已经能在controll 中查出数据,但 generator 还是出错:@Before(BlogInterceptor.class)
public class BlogController extends Controller {
public void index() {

setAttr("blogPage", Blog.me.paginate(getParaToInt(0, 1), 100));
///render("blog.html");
renderJson() ;



} 上面的代码已能正确返回数据: {"blogPage":{"lastPage":true,"pageSize":100,"pageNumber":1,"list":[{"content":"222","id":1,"title":"1","tempcolumn":0,"temprownumber":1},{"content":"qqqqq","id":2,"title":"2","tempcolumn":0,"temprownumber":2}],"firstPage":true,"totalRow":2,"totalPage":1}} 但用generator 生成代码仍然出错(这个错好像跟原来不一样?):
2016-12-08 16:23:47
[WARN]-[Thread: Timer-0]-[com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector.run()]: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@d67d61 -- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending tasks!

2016-12-08 16:23:47
[WARN]-[Thread: Timer-0]-[com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector.run()]: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@d67d61 -- APPARENT DEADLOCK!!! Complete Status:
Managed Threads: 3
Active Threads: 3
Active Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@e7736c (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@14ad296 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1479a6b (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
Pending Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1eae775
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@101b455
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@e6529c
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1399ae5
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@e8709d
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@397cea
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@380dbe
Pool thread stack traces:
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
java.lang.Thread.sleep(Native Method)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
java.lang.Thread.sleep(Native Method)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
java.lang.Thread.sleep(Native Method)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)



2016-12-08 16:23:56
[WARN]-[Thread: com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2]-[com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run()]: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@14ad296 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
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)
Exception in thread "main" java.lang.RuntimeException: java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.jfinal.plugin.activerecord.generator.MetaBuilder.build(MetaBuilder.java:102)
at com.jfinal.plugin.activerecord.generator.Generator.generate(Generator.java:210)
at com.demo.common.model._JFinalDemoGenerator.main(_JFinalDemoGenerator.java:45)
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at com.jfinal.plugin.activerecord.generator.MetaBuilder.build(MetaBuilder.java:90)
... 2 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
... 4 more

2016-12-08 16:23:56
[WARN]-[Thread: com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1]-[com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run()]: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@e7736c -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
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)

2016-12-08 16:23:56
[WARN]-[Thread: com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0]-[com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run()]: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1479a6b -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
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

2016-12-08 16:42

@gxlzlijng 以前的问题不再出现,证明以前是我说过的连接不上的问题,现在的问题,全是 "WARN",根本不是异常,只需要将日志级别调高就没有了,当然,这个问题不能无视,只需要将 c3p0 换成 DruidPlugin 即可打完收枪

gxlzlijng

2016-12-09 09:42

@JFinal @JFinal C3P0 跟Druid 配置好像不一样,可以发个标准的配置示例参考下吗,谢谢!

JFinal

2016-12-09 09:50

下面这个配置是 jfinal 社区的配置,可参考:
Prop p = PropKit.use("jfinal_config.txt");
DruidPlugin dp= new DruidPlugin(p.get("jdbcUrl"), p.get("user"), p.get("password").trim());
WallFilter wallFilter = new WallFilter();
wallFilter.setDbType("mysql");
dp.addFilter(wallFilter);
dp.addFilter(new StatFilter()); // 添加 StatFilter 才会有统计数据
me.add(dp);

ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
arp.setTransactionLevel(Connection.TRANSACTION_READ_COMMITTED);
_MappingKit.mapping(arp);
me.add(arp);

gxlzlijng

2016-12-09 15:03

@JFinal 谢谢波总,顺便问一下 jfinal_config.txt 部署到生产时会被编绎加密吗?

eternity733

2016-12-13 11:24

@gxlzlijng 部署在服务器了,你还要加密?呵呵

eternity733

2016-12-13 11:25

@JFinal TableMeta 数量为 0,不生成任何文件,这个问题在哪里有帖子解决

热门反馈

扫码入社