spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.66k stars 38.14k forks source link

Spring embedded database fails to execute script after encoding changes [SPR-8562] #13206

Closed spring-projects-issues closed 12 years ago

spring-projects-issues commented 13 years ago

Luca Preziati opened SPR-8562 and commented

If the Script sql used to popolate Embedded Db, like this

contains new line in sql command, the import failed with uncomprensible error. I think should be necessary throw a specific exception or better permit space and load the sql command separated by character ; --- **Affects:** 3.0.4 **Attachments:** - [error.sql](https://jira.spring.io/secure/attachment/18516/error.sql) (_11.67 kB_) - [typeRegistryCreate.sql](https://jira.spring.io/secure/attachment/18515/typeRegistryCreate.sql) (_40 bytes_)
spring-projects-issues commented 13 years ago

Juergen Hoeller commented

What exactly is the error that you're getting? Spring 3.0.4 should actually allow for newlines there... Please double-check the Spring version that you're using.

Juergen

spring-projects-issues commented 13 years ago

Luca Preziati commented

Script which failed

spring-projects-issues commented 13 years ago

Luca Preziati commented

Spring Exception

spring-projects-issues commented 13 years ago

Luca Preziati commented

Error is related to file Encoding, tomcat start with UTF-8 Encoding, but when i change in Windows file encoding from ISO8852-9 to UTF8. But as you can see, the exception is impossible to understand....

org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "CREATE[*] TABLE PROVA (ID VARCHAR2(45)) "; SQL statement: CREATE TABLE PROVA (id VARCHAR2(45)) [42000-158]

Sorry for the naming of the bug, I related to the new line, but obviusly I also change the file encoding, recreating file.

spring-projects-issues commented 13 years ago

Juergen Hoeller commented

I'm afraid there is not much we can do here automatically since the actual encoding in a file is hard to detect. You'll need to specify the encoding explicitly.

If the encoding in your file differs from the platform encoding, consider specifying the "sqlScriptEncoding" property on ResourceDatabasePopulator. This is unfortunately not exposed in the jdbc namespace yet; I've added such an "encoding" attribute for Spring 3.1. On Spring 3.0, you'd need to avoid the namespace and fall back to traditional Spring bean definitions: Define the ResourceDatabasePopulator as a regular bean - using its "sqlScriptEncoding" property - and set that populator bean on the "databasePopulator" property of your EmbeddedDatabaseFactoryBean.

Juergen