最近要使用junit 和dbunit做单元测试,发现使用jfinal的c3p0的时候,执行activeRecordPlugin.start()会报错。请问有人碰到这个问题吗?有啥好的 解决方法求分享一下。代码如下:
C3p0Plugin c3p0Plugin = new C3p0Plugin("jdbc:hsqldb:mem:my-project-test;shutdown=true", "", "");c3p0Plugin.start();
Connection connection = c3p0Plugin.getDataSource().getConnection();
Statement statement = connection.createStatement();
statement.execute("CREATE TABLE users ( id INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1), username VARCHAR(10), first_name VARCHAR(10), last_name VARCHAR(10) )");
statement.close();
ActiveRecordPlugin activeRecordPlugin = new ActiveRecordPlugin(c3p0Plugin);
activeRecordPlugin.addMapping("users", User.class); activeRecordPlugin.start();
ActiveRecordPlugin脱离web使用,详见jfinal2.0手册5.12章节。
错误信息如下:
CannotcreateTableobject,maybethetableusersisnotexists.
Exceptioninthread"main"com.jfinal.plugin.activerecord.ActiveRecordException:java.sql.SQLSyntaxErrorException:userlacksprivilegeorobjectnotfound:
atcom.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:91)
atcom.jfinal.plugin.activerecord.ActiveRecordPlugin.start(ActiveRecordPlugin.java:171)
atdao.TestUser.main(TestUser.java:24)
atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
atjava.lang.reflect.Method.invoke(Method.java:483)
atcom.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Causedby:java.sql.SQLSyntaxErrorException:userlacksprivilegeorobjectnotfound:
atorg.hsqldb.jdbc.JDBCUtil.sqlException(UnknownSource)
atorg.hsqldb.jdbc.JDBCUtil.sqlException(UnknownSource)
atorg.hsqldb.jdbc.JDBCStatement.fetchResult(UnknownSource)
atorg.hsqldb.jdbc.JDBCStatement.executeQuery(UnknownSource)
atcom.mchange.v2.c3p0.impl.NewProxyStatement.executeQuery(NewProxyStatement.java:35)
atcom.jfinal.plugin.activerecord.TableBuilder.doBuild(TableBuilder.java:106)
atcom.jfinal.plugin.activerecord.TableBuilder.build(TableBuilder.java:84)
...7more
Causedby:org.hsqldb.HsqlException:userlacksprivilegeorobjectnotfound:
atorg.hsqldb.error.Error.error(UnknownSource)
atorg.hsqldb.error.Error.error(UnknownSource)
atorg.hsqldb.ParserDQL.readTableName(UnknownSource)
atorg.hsqldb.ParserDQL.readTableOrSubquery(UnknownSource)
atorg.hsqldb.ParserDQL.XreadTableReference(UnknownSource)
atorg.hsqldb.ParserDQL.XreadFromClause(UnknownSource)
atorg.hsqldb.ParserDQL.XreadTableExpression(UnknownSource)
atorg.hsqldb.ParserDQL.XreadQuerySpecification(UnknownSource)
atorg.hsqldb.ParserDQL.XreadSimpleTable(UnknownSource)
atorg.hsqldb.ParserDQL.XreadQueryPrimary(UnknownSource)
atorg.hsqldb.ParserDQL.XreadQueryTerm(UnknownSource)
atorg.hsqldb.ParserDQL.XreadQueryExpressionBody(UnknownSource)
atorg.hsqldb.ParserDQL.XreadQueryExpression(UnknownSource)
atorg.hsqldb.ParserDQL.compileCursorSpecification(UnknownSource)
atorg.hsqldb.ParserCommand.compilePart(UnknownSource)
atorg.hsqldb.ParserCommand.compileStatements(UnknownSource)
atorg.hsqldb.Session.executeDirectStatement(UnknownSource)
atorg.hsqldb.Session.execute(UnknownSource)
...12more
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。