如何在带有jdbc的字段中插入带分号的值?

时间:2019-02-15 14:10:40

标签: sql spring jdbc h2

我有:

`<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中。

查询:

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"

OR

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

我想要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 :(得分:0)

尝试:

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