سؤال

DBUnit is throwing an exception when trying to run an insert statement on an in-memory DB2 database:

org.dbunit.dataset.DataSetException: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "HOUR" at line 1, column 45.

I realize that "HOUR" is a reserved keyword in DB2 but I'm not sure how to get dbunit to escape this reserved keyword.

هل كانت مفيدة؟

المحلول

Found that the default escape pattern for dbunit is the null string, so dbunit recognized the reserved keyword and tried to escape it with a null string. To change this, I used the following to change the escape pattern for reserved keywords and now it's working:

dbunitConn.getConfig().setProperty(DatabaseConfig.PROPERTY_ESCAPE_PATTERN, "\"?\"");

نصائح أخرى

You could try using properties on database configurations :

DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_ESCAPE_PATTERN, "[HOUR]");
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top