Как вставить значение с точкой с запятой в поле с JDBC? - PullRequest
0 голосов
/ 15 февраля 2019

У меня есть:

`<beans profile="h2">
        <import resource="classpath:config/db-config.xml" />
        <context:property-placeholder location="classpath:config/batch.h2.properties" />
        <jdbc:initialize-database data-source="dataSource">
          <jdbc:script location="classpath:rendicontazione/configurazione/create_configurazione.sql"/>
          <jdbc:script location="classpath:rendicontazione/configurazione/insert_configurazione.sql"/>
        </jdbc:initialize-database>
        <import resource="classpath:config/batch-context-test.xml" />
    </beans>`

ошибка лежит внутри insert_configurazione.sql.

QUERY:

INSERT INTO CONFIGURAZIONE (DOMINIO,CHIAVE,VALORE) 
     VALUES ('XXX','YYY','a;b;c;d;e;f');

Если я попытаюсь с:

INSERT INTO CONFIGURAZIONE (DOMINIO,CHIAVE,VALORE) 
     VALUES ('XXX','YYY','"a;b;c;d;e;f"');

Строка вставлена, но значение VALORE равно "a;b;c;d;e;f".

ИЛИ

INSERT INTO CONFIGURAZIONE (DOMINIO,CHIAVE,VALORE) VALUES ('XXX','YYY','a\;b\;c\;d\;e\;f'); Результат: a\;b\;c\;d\;e\;f\;

Iхотите значение VALORE = a;b;c;d;e;f

Stacktrace:

INSERT INTO CONFIGURAZIONE (DOMINIO,CHIAVE,VALORE) VALUES ('XXX','YYY','a [42000-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.message.DbException.getSyntaxError(DbException.java:203)
at org.h2.command.Parser.getSyntaxError(Parser.java:548)
at org.h2.command.Parser.checkRunOver(Parser.java:4080)
at org.h2.command.Parser.initialize(Parser.java:3989)
at org.h2.command.Parser.parse(Parser.java:322)
at org.h2.command.Parser.parse(Parser.java:311)
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.JdbcStatement.executeInternal(JdbcStatement.java:217)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:205)
at com.jolbox.bonecp.StatementHandle.execute(StatementHandle.java:254)
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:473)
... 55 more

1 Ответ

0 голосов
/ 15 февраля 2019

попробуй:

INSERT INTO CONFIGURAZIONE (DOMINIO,CHIAVE,VALORE) 
     VALUES ('XXX','YYY','"a\;b\;c\;d\;e\;f"');
...