You're using Spring 2.5.2, but referring to the 2.5.6 documentation.
Up vote 5 down vote favorite share g+ share fb share tw.
I want to load SQL script files for my unit tests. As I am using Spring 2.5.2, I decided to use the SimpleJdbcTestUtils.executeScript() method to load my script file, using the following code: DriverManagerDataSource dataSource = ... // getting my DataSource defined in my Spring context SimpleJdbcTemplate template = new SimpleJdbcTemplate(dataSource); Resource resource = new ClassPathResource("/create-table. Sql"); SimpleJdbcTestUtils.
ExecuteSqlScript(template, resource, true); If I write each SQL statement in one line in the create-table. Sql file, then everything is ok. But if I write a statement on multiple lines, then I get an error, even if the statement is finished by a ;.
Working script : CREATE TABLE T_FOO (ID NUMERIC PRIMARY KEY, DATEID TIMESTAMP, IS_ACTIVE INTEGER DEFAULT 0 NOT NULL); CREATE TABLE T_BAR (ID NUMERIC PRIMARY KEY, DATEID TIMESTAMP, IS_ACTIVE INTEGER DEFAULT 0 NOT NULL); Not working script: CREATE TABLE T_FOO ( ID NUMERIC PRIMARY KEY, DATEID TIMESTAMP, IS_ACTIVE INTEGER DEFAULT 0 NOT NULL); CREATE TABLE T_BAR ( ID NUMERIC PRIMARY KEY, DATEID TIMESTAMP, IS_ACTIVE INTEGER DEFAULT 0 NOT NULL); Error on second file: org.springframework.jdbc. BadSqlGrammarException: StatementCallback; bad SQL grammar CREATE TABLE T_FOO (; nested exception is java.sql. SQLException: Unexpected token: in statement CREATE TABLE T_FOO ( at org.springframework.jdbc.support.
SQLStateSQLExceptionTranslator. Translate(SQLStateSQLExceptionTranslator. Java:111) at org.springframework.jdbc.support.
SQLErrorCodeSQLExceptionTranslator. Translate(SQLErrorCodeSQLExceptionTranslator. Java:322) at org.springframework.jdbc.core.JdbcTemplate.
Execute(JdbcTemplate. Java:404) at org.springframework.jdbc.core.JdbcTemplate. Update(JdbcTemplate.
Java:519) at org.springframework.jdbc.core.simple. SimpleJdbcTemplate. Update(SimpleJdbcTemplate.
Java:237) at org.springframework.test.jdbc. SimpleJdbcTestUtils. ExecuteSqlScript(SimpleJdbcTestUtils.
Java:150) at org.springframework.test.jdbc. SimpleJdbcTestUtils. ExecuteSqlScript(SimpleJdbcTestUtils.
Java:113) at foo.bar.HsqldbUtils. Run(HsqldbUtils. Java:95) at foo.bar.SomeUnitTest.
ExecuteTests(SomeUnitTest. Java:63) at sun.reflect. NativeMethodAccessorImpl.
Invoke0(Native Method) at sun.reflect. NativeMethodAccessorImpl. Invoke(NativeMethodAccessorImpl.
Java:39) at sun.reflect. DelegatingMethodAccessorImpl. Invoke(DelegatingMethodAccessorImpl.
Java:25) at java.lang.reflect.Method. Invoke(Method. Java:597) at org.junit.internal.runners.
TestMethodRunner. ExecuteMethodBody(TestMethodRunner. Java:99) at org.junit.internal.runners.
TestMethodRunner. RunUnprotected(TestMethodRunner. Java:81) at org.junit.internal.runners.
BeforeAndAfterRunner. RunProtected(BeforeAndAfterRunner. Java:34) at org.junit.internal.runners.
TestMethodRunner. RunMethod(TestMethodRunner. Java:75) at org.junit.internal.runners.
TestMethodRunner. Run(TestMethodRunner. Java:45) at org.junit.internal.runners.
TestClassMethodsRunner. InvokeTestMethod(TestClassMethodsRunner. Java:71) at org.junit.internal.runners.
TestClassMethodsRunner. Run(TestClassMethodsRunner. Java:35) at org.junit.internal.runners.
TestClassRunner$1. RunUnprotected(TestClassRunner. Java:42) at org.junit.internal.runners.
BeforeAndAfterRunner. RunProtected(BeforeAndAfterRunner. Java:34) at org.junit.internal.runners.TestClassRunner.
Run(TestClassRunner. Java:52) at org.eclipse.jdt.internal. Junit4.runner.
JUnit4TestReference. Run(JUnit4TestReference. Java:45) at org.eclipse.jdt.internal.junit.runner.TestExecution.
Run(TestExecution. Java:38) at org.eclipse.jdt.internal.junit.runner. RemoteTestRunner.
RunTests(RemoteTestRunner. Java:460) at org.eclipse.jdt.internal.junit.runner. RemoteTestRunner.
RunTests(RemoteTestRunner. Java:673) at org.eclipse.jdt.internal.junit.runner. RemoteTestRunner.
Run(RemoteTestRunner. Java:386) at org.eclipse.jdt.internal.junit.runner. RemoteTestRunner.
Main(RemoteTestRunner. Java:196) Caused by: java.sql. SQLException: Unexpected token: in statement CREATE TABLE T_FOO ( at org.hsqldb.jdbc.Util.
SqlException(Unknown Source) at org.hsqldb.jdbc.jdbcStatement. FetchResult(Unknown Source) at org.hsqldb.jdbc.jdbcStatement. ExecuteUpdate(Unknown Source) at org.springframework.jdbc.core.
JdbcTemplate$1UpdateStatementCallback. DoInStatement(JdbcTemplate. Java:509) at org.springframework.jdbc.core.JdbcTemplate.
Execute(JdbcTemplate. Java:393) As I am willing to create more complex tables, I prefer to write the SQL instruction in a more readable way, so using several lines. Is there a way to do that?
Java spring jdbc hsqldb link|improve this question edited Feb 20 '10 at 16:32skaffman114k8136227 asked Feb 19 '10 at 13:13romaintaz16.3k54491 82% accept rate.
Nov 24 '10 at 9:17 @Boris This site seems to have a copy of the SO question... Need some investigations about that. Thanks. – romaintaz Nov 24 '10 at 13:52 1 @Boris Look at this: meta.stackoverflow.com/questions/58369 It seems OK then... – romaintaz Nov 24 '10 at 13:54.
You're using Spring 2.5.2, but referring to the 2.5.6 documentation. If you look at the javadoc for 2.5.2 (see here), you'll note that it doesn't support multi-line scripts. This was apparently resolved in 2.5.4 (issue here).
You should upgrade to 2.5.6, or better yet, 3.0.x.
You are totally right! I must update my bookmark or my Spring version indeed ;) – romaintaz Feb 20 '10 at 18:22 1 Spring updated to 2.5.6, the problem is solved. Thanks!
– romaintaz Feb 22 '10 at 9:10.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.