Caused by: java.sql.SQLException: Error executing stmt ordererror

博主在运行JUnit时使用order字段报错,原因是数据库SQL语句中有order by,order为专有名词。解决方法是将order改成其他字段。

今天我在运行junit的时候,用了一个order字段:

@Constraints.Required
@Column(columnDefinition = "int(11) NOT NULL COMMENT '顺序'")
private Integer order;

然后就报错了:

com.google.inject.CreationException: Unable to create injector, see the following errors:

1) Error injecting constructor, javax.persistence.PersistenceException: Failed to run script
  at play.db.ebean.EbeanDynamicEvolutions.<init>(EbeanDynamicEvolutions.java:35)
  at play.db.ebean.EbeanDynamicEvolutions.class(EbeanDynamicEvolutions.java:32)
  while locating play.db.ebean.EbeanDynamicEvolutions
  at Module.configure(Module.java:46) (via modules: com.google.inject.util.Modules$OverrideModule -> Module)
  while locating play.api.db.evolutions.DynamicEvolutions
  while locating play.api.db.evolutions.ApplicationEvolutionsProvider
  at play.api.db.evolutions.EvolutionsModule.<init>(EvolutionsModule.scala:20):
Binding(class play.api.db.evolutions.ApplicationEvolutions to ProviderConstructionTarget(class play.api.db.evolutions.ApplicationEvolutionsProvider) eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$4)
  while locating play.api.db.evolutions.ApplicationEvolutions
Caused by: javax.persistence.PersistenceException: Failed to run script
	at io.ebeaninternal.dbmigration.DdlGenerator.runScript(DdlGenerator.java:126)
	at io.ebeaninternal.dbmigration.DdlGenerator.runCreateSql(DdlGenerator.java:154)
	at io.ebeaninternal.dbmigration.DdlGenerator.runDdl(DdlGenerator.java:93)
	at io.ebeaninternal.dbmigration.DdlGenerator.execute(DdlGenerator.java:68)
	at io.ebeaninternal.server.core.DefaultServer.executePlugins(DefaultServer.java:311)
	at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:146)
	at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:45)
	at io.ebean.EbeanServerFactory.createInternal(EbeanServerFactory.java:109)
	at io.ebean.EbeanServerFactory.create(EbeanServerFactory.java:70)
	at play.db.ebean.EbeanDynamicEvolutions.lambda$start$3(EbeanDynamicEvolutions.java:49)
	at java.util.HashMap.forEach(HashMap.java:1288)
	at play.db.ebean.EbeanDynamicEvolutions.start(EbeanDynamicEvolutions.java:49)
	at play.db.ebean.EbeanDynamicEvolutions.<init>(EbeanDynamicEvolutions.java:38)
	at play.db.ebean.EbeanDynamicEvolutions$$FastClassByGuice$$52c94231.newInstance(<generated>)
	at com.google.inject.internal.DefaultConstructionProxyFactory$FastClassProxy.newInstance(DefaultConstructionProxyFactory.java:89)
	at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:111)
	at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)
	at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:268)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
	at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
	at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:194)
	at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
	at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
	at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
	at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:194)
	at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
	at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1019)
	at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
	at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1015)
	at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1054)
	at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:409)
	at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:404)
	at play.api.inject.ContextClassLoaderInjector.$anonfun$instanceOf$2(Injector.scala:117)
	at play.api.inject.ContextClassLoaderInjector.withContext(Injector.scala:126)
	at play.api.inject.ContextClassLoaderInjector.instanceOf(Injector.scala:117)
	at play.api.db.evolutions.ApplicationEvolutionsProvider.get$lzycompute(EvolutionsModule.scala:49)
	at play.api.db.evolutions.ApplicationEvolutionsProvider.get(EvolutionsModule.scala:49)
	at play.api.db.evolutions.ApplicationEvolutionsProvider.get(EvolutionsModule.scala:40)
	at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
	at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72)
	at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61)
	at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
	at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
	at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:194)
	at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
	at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:205)
	at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:199)
	at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1085)
	at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199)
	at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180)
	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
	at com.google.inject.Guice.createInjector(Guice.java:99)
	at com.google.inject.Guice.createInjector(Guice.java:84)
	at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:185)
	at play.inject.guice.GuiceBuilder.injector(GuiceBuilder.java:221)
	at play.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.java:156)
	at AbstractTest.setup(AbstractTest.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.sql.SQLException: Error executing stmt[create table et_survey_question ( id                            bigint auto_increment not null, survey_id                     int(11) NOT NULL COMMENT '问卷id', question                      longtext NOT NULL COMMENT '问卷项', deleted                       bit(1) NOT NULL COMMENT '是否删除', order                         int(11) NOT NULL COMMENT '顺序', constraint pk_et_survey_question primary key (id) )] error[Syntax error in SQL statement "CREATE TABLE ET_SURVEY_QUESTION ( ID                            BIGINT AUTO_INCREMENT NOT NULL, SURVEY_ID                     INT(11) NOT NULL COMMENT '问卷id', QUESTION                      LONGTEXT NOT NULL COMMENT '问卷项', DELETED                       BIT(1) NOT NULL COMMENT '是否删除', ORDER[*]                         INT(11) NOT NULL COMMENT '顺序', CONSTRAINT PK_ET_SURVEY_QUESTION PRIMARY KEY (ID) ) "; expected "identifier"; SQL statement:
create table et_survey_question ( id                            bigint auto_increment not null, survey_id                     int(11) NOT NULL COMMENT '问卷id', question                      longtext NOT NULL COMMENT '问卷项', deleted                       bit(1) NOT NULL COMMENT '是否删除', order                         int(11) NOT NULL COMMENT '顺序', constraint pk_et_survey_question primary key (id) ) [42001-197]]
	at io.ebean.migration.ddl.DdlRunner.runStatement(DdlRunner.java:113)
	at io.ebean.migration.ddl.DdlRunner.runStatements(DdlRunner.java:70)
	at io.ebean.migration.ddl.DdlRunner.runAll(DdlRunner.java:49)
	at io.ebeaninternal.dbmigration.DdlGenerator.runScript(DdlGenerator.java:118)
	... 84 more
Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "CREATE TABLE ET_SURVEY_QUESTION ( ID                            BIGINT AUTO_INCREMENT NOT NULL, SURVEY_ID                     INT(11) NOT NULL COMMENT '问卷id', QUESTION                      LONGTEXT NOT NULL COMMENT '问卷项', DELETED                       BIT(1) NOT NULL COMMENT '是否删除', ORDER[*]                         INT(11) NOT NULL COMMENT '顺序', CONSTRAINT PK_ET_SURVEY_QUESTION PRIMARY KEY (ID) ) "; expected "identifier"; SQL statement:
create table et_survey_question ( id                            bigint auto_increment not null, survey_id                     int(11) NOT NULL COMMENT '问卷id', question                      longtext NOT NULL COMMENT '问卷项', deleted                       bit(1) NOT NULL COMMENT '是否删除', order                         int(11) NOT NULL COMMENT '顺序', constraint pk_et_survey_question primary key (id) ) [42001-197]
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:357)
	at org.h2.message.DbException.getSyntaxError(DbException.java:217)
	at org.h2.command.Parser.readColumnIdentifier(Parser.java:3507)
	at org.h2.command.Parser.parseTableColumnDefinition(Parser.java:6661)
	at org.h2.command.Parser.parseCreateTable(Parser.java:6570)
	at org.h2.command.Parser.parseCreate(Parser.java:4615)
	at org.h2.command.Parser.parsePrepared(Parser.java:380)
	at org.h2.command.Parser.parse(Parser.java:335)
	at org.h2.command.Parser.parse(Parser.java:307)
	at org.h2.command.Parser.prepareCommand(Parser.java:278)
	at org.h2.engine.Session.prepareLocal(Session.java:611)
	at org.h2.engine.Session.prepareCommand(Session.java:549)
	at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1247)
	at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:76)
	at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:304)
	at com.zaxxer.hikari.pool.ProxyConnection.prepareStatement(ProxyConnection.java:318)
	at com.zaxxer.hikari.pool.HikariProxyConnection.prepareStatement(HikariProxyConnection.java)
	at io.ebean.migration.ddl.DdlRunner.runStatement(DdlRunner.java:105)
	... 87 more

2) Error injecting constructor, javax.persistence.PersistenceException: Failed to run script
  at play.db.ebean.EbeanDynamicEvolutions.<init>(EbeanDynamicEvolutions.java:35)
  at play.db.ebean.EbeanDynamicEvolutions.class(EbeanDynamicEvolutions.java:32)
  while locating play.db.ebean.EbeanDynamicEvolutions
  at Module.configure(Module.java:46) (via modules: com.google.inject.util.Modules$OverrideModule -> Module)
  while locating play.api.db.evolutions.DynamicEvolutions
Caused by: javax.persistence.PersistenceException: Failed to run script
	at io.ebeaninternal.dbmigration.DdlGenerator.runScript(DdlGenerator.java:126)
	at io.ebeaninternal.dbmigration.DdlGenerator.runCreateSql(DdlGenerator.java:154)
	at io.ebeaninternal.dbmigration.DdlGenerator.runDdl(DdlGenerator.java:93)
	at io.ebeaninternal.dbmigration.DdlGenerator.execute(DdlGenerator.java:68)
	at io.ebeaninternal.server.core.DefaultServer.executePlugins(DefaultServer.java:311)
	at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:146)
	at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:45)
	at io.ebean.EbeanServerFactory.createInternal(EbeanServerFactory.java:109)
	at io.ebean.EbeanServerFactory.create(EbeanServerFactory.java:70)
	at play.db.ebean.EbeanDynamicEvolutions.lambda$start$3(EbeanDynamicEvolutions.java:49)
	at java.util.HashMap.forEach(HashMap.java:1288)
	at play.db.ebean.EbeanDynamicEvolutions.start(EbeanDynamicEvolutions.java:49)
	at play.db.ebean.EbeanDynamicEvolutions.<init>(EbeanDynamicEvolutions.java:38)
	at play.db.ebean.EbeanDynamicEvolutions$$FastClassByGuice$$52c94231.newInstance(<generated>)
	at com.google.inject.internal.DefaultConstructionProxyFactory$FastClassProxy.newInstance(DefaultConstructionProxyFactory.java:89)
	at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:111)
	at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)
	at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:268)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
	at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
	at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:194)
	at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
	at com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
	at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
	at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
	at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:194)
	at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
	at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:205)
	at com.google.inject.internal.InternalInjectorCreator$1.call(InternalInjectorCreator.java:199)
	at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1085)
	at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:199)
	at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:180)
	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
	at com.google.inject.Guice.createInjector(Guice.java:99)
	at com.google.inject.Guice.createInjector(Guice.java:84)
	at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:185)
	at play.inject.guice.GuiceBuilder.injector(GuiceBuilder.java:221)
	at play.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.java:156)
	at AbstractTest.setup(AbstractTest.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.sql.SQLException: Error executing stmt[create table et_activity ( id                            bigint auto_increment not null, title                         varchar(255), creator_id                    bigint, introduction                  varchar(255), content                       varchar(255), enroll_start_time             datetime, enroll_end_time               datetime, max_enroll_number             bigint, current_enroll_number         bigint, notice_news                   varchar(255), start_time                    datetime, end_time                      datetime, sign_in_start_time            datetime, sign_in_end_time              datetime, file_id                       bigint, location                      varchar(255), location_id                   bigint, type                          tinyint, qrcode_content                varchar(255), qrcode_id                     bigint, status                        tinyint, delete_time                   datetime, create_time                   datetime not null, update_time                   datetime not null, constraint pk_et_activity primary key (id) )] error[Table "ET_ACTIVITY" already exists; SQL statement:
create table et_activity ( id                            bigint auto_increment not null, title                         varchar(255), creator_id                    bigint, introduction                  varchar(255), content                       varchar(255), enroll_start_time             datetime, enroll_end_time               datetime, max_enroll_number             bigint, current_enroll_number         bigint, notice_news                   varchar(255), start_time                    datetime, end_time                      datetime, sign_in_start_time            datetime, sign_in_end_time              datetime, file_id                       bigint, location                      varchar(255), location_id                   bigint, type                          tinyint, qrcode_content                varchar(255), qrcode_id                     bigint, status                        tinyint, delete_time                   datetime, create_time                   datetime not null, update_time                   datetime not null, constraint pk_et_activity primary key (id) ) [42101-197]]
	at io.ebean.migration.ddl.DdlRunner.runStatement(DdlRunner.java:113)
	at io.ebean.migration.ddl.DdlRunner.runStatements(DdlRunner.java:70)
	at io.ebean.migration.ddl.DdlRunner.runAll(DdlRunner.java:49)
	at io.ebeaninternal.dbmigration.DdlGenerator.runScript(DdlGenerator.java:118)
	... 63 more
Caused by: org.h2.jdbc.JdbcSQLException: Table "ET_ACTIVITY" already exists; SQL statement:
create table et_activity ( id                            bigint auto_increment not null, title                         varchar(255), creator_id                    bigint, introduction                  varchar(255), content                       varchar(255), enroll_start_time             datetime, enroll_end_time               datetime, max_enroll_number             bigint, current_enroll_number         bigint, notice_news                   varchar(255), start_time                    datetime, end_time                      datetime, sign_in_start_time            datetime, sign_in_end_time              datetime, file_id                       bigint, location                      varchar(255), location_id                   bigint, type                          tinyint, qrcode_content                varchar(255), qrcode_id                     bigint, status                        tinyint, delete_time                   datetime, create_time                   datetime not null, update_time                   datetime not null, constraint pk_et_activity primary key (id) ) [42101-197]
	at org.h2.message.DbException.getJdbcSQLException(DbException.java:357)
	at org.h2.message.DbException.get(DbException.java:179)
	at org.h2.message.DbException.get(DbException.java:155)
	at org.h2.command.ddl.CreateTable.update(CreateTable.java:86)
	at org.h2.command.CommandContainer.update(CommandContainer.java:102)
	at org.h2.command.Command.executeUpdate(Command.java:261)
	at org.h2.jdbc.JdbcPreparedStatement.execute(JdbcPreparedStatement.java:249)
	at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
	at io.ebean.migration.ddl.DdlRunner.runStatement(DdlRunner.java:106)
	... 66 more

2 errors

	at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:470)
	at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:184)
	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
	at com.google.inject.Guice.createInjector(Guice.java:99)
	at com.google.inject.Guice.createInjector(Guice.java:84)
	at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:185)
	at play.inject.guice.GuiceBuilder.injector(GuiceBuilder.java:221)
	at play.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.java:156)
	at AbstractTest.setup(AbstractTest.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)


java.lang.NullPointerException
	at play.test.Helpers.stop(Helpers.java:606)
	at AbstractTest.teardown(AbstractTest.java:42)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

解决方法

@Constraints.Required
@Column(columnDefinition = "int(11) NOT NULL COMMENT '顺序'")
private Integer order_num;

把order改成其他的就行了,因为order数据库里面的sql语句有个order by,是专有名词,我瞬间被打脸了。

 

### Java中 `java.sql.SQLException` 导致的无效列索引问题解决方案 #### 1. 原因分析 当遇到 `java.sql.SQLException: 索引中丢失 IN 或 OUT 参数` 的错误时,通常是因为 SQL 查询中的占位符数量与实际绑定参数的数量不匹配。例如,在 JDBC 中使用 `PreparedStatement` 执行查询时,如果 SQL 语句中的问号 (`?`) 数量与传递给 `setXXX()` 方法的实际参数数量不符,则会抛出此异常[^1]。 另一个常见原因是动态 SQL 的编写方式不当。比如在 MyBatis 动态 SQL 场景下,条件判断逻辑可能导致最终生成的 SQL 不符合预期,从而引发无效列索引的问题[^5]。 此外,某些情况下,SQL 字符串拼接的方式也可能引入潜在风险。例如,直接通过字符串连接构建 SQL 可能导致特殊字符(如单引号)未被正确转义,进而触发异常[^3]。 --- #### 2. 解决方案 ##### (1)确保占位符与参数数量一致 检查 SQL 语句中的占位符数量是否与传递的参数数组长度相匹配。例如: ```java String sql = "INSERT INTO table_name (column1, column2) VALUES (?, ?)"; jdbcTemplate.update(sql, new Object[]{value1, value2}); ``` 上述代码中,SQL 语句有两个占位符,而参数数组也提供了两个值。如果不满足这种一一对应关系,就会发生异常[^2]。 ##### (2)优化动态 SQL 编写 对于复杂的动态 SQL,建议采用工具库(如 MyBatis)来简化处理流程,并严格控制条件分支逻辑。以下是一个改进后的 MyBatis 配置示例: ```xml <select id="selectUsers" resultType="User"> SELECT * FROM users <where> <if test="name != null and name != ''">AND name LIKE CONCAT('%', #{name}, '%')</if> <if test="age != null">AND age = #{age}</if> </where> </select> ``` 在此配置中,`<where>` 和 `<if>` 标签能够自动管理多余的 `AND` 关键字,减少手动调整的风险。 ##### (3)避免硬编码 SQL 拼接 尽量避免直接拼接 SQL 字符串,尤其是涉及用户输入的部分。推荐使用预编译语句或 ORM 工具替代原始 SQL 构建方法。例如: ```java // 错误做法:容易引起语法错误或安全漏洞 String sql = "SELECT * FROM users WHERE username='" + userInput + "'"; // 正确做法:利用 PreparedStatement 绑定参数 String sql = "SELECT * FROM users WHERE username=?"; PreparedStatement pstmt = connection.prepareStatement(sql); pstmt.setString(1, userInput); ResultSet rs = pstmt.executeQuery(); ``` 这种方法不仅提高了安全性,还能有效规避由于参数格式化不当引起的异常[^4]。 ##### (4)升级旧版系统 针对遗留系统的兼容性问题,可以考虑逐步迁移至更现代化的技术栈。虽然短期内可能无法完全替换现有实现,但仍可通过局部改造降低维护成本。例如,将敏感操作封装到独立模块中,统一处理参数转义和边界校验。 --- #### 3. 总结 要彻底解决 `java.sql.SQLException: 无效列索引` 的问题,需从以下几个方面入手: - **核对 SQL 占位符与参数的一致性** - **优化复杂查询的动态生成机制** - **杜绝危险的字符串拼接行为** - **评估并改善陈旧架构的设计缺陷** 通过以上措施,可显著提升程序稳定性,同时增强抵御外部攻击的能力。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

农民小飞侠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值