org.postgresql.util.PSQLException: ERROR: syntax error at or near "user"
org.postgresql.util.PSQLException: ERROR: syntax error at or near "user"
<dataset>
<user id="1" created_date='2017-01-01 00:00:00' email="" user_name="root"/>
</dataset>
xml 上面给了我错误。问题是我为用户保留了字。我该如何解决这个问题。有链接吗?
已更新
我正在使用 spring 引导,spring 数据 jpa,spring-test-dbunit,dbunit,postgresql
根据此论坛 https://sourceforge.net/p/dbunit/mailman/message/20643023/ DBUnit 似乎没有办法“引用”table 名称。但是,如果您出于某种原因不想重命名 table 或使用遗留数据库
,则可以配置 DatabaseDataSourceConnectionFactoryBean
@Configuration
public class Custom.... {
@Autowired
private DataSource dataSource;
@Bean
public DatabaseConfigBean dbUnitDatabaseConfig() {
DatabaseConfigBean dbConfigBean = new DatabaseConfigBean();
// dbConfigBean.setDatatypeFactory(new PostgresqlDataTypeFactory());
dbConfigBean.setQualifiedTableNames(true);
return dbConfigBean;
}
@Bean
public DatabaseDataSourceConnectionFactoryBean dbUnitDatabaseConnection() {
DatabaseDataSourceConnectionFactoryBean databaseDataSourceConnectionFactoryBean = new DatabaseDataSourceConnectionFactoryBean(dataSource);
databaseDataSourceConnectionFactoryBean.setDatabaseConfig(dbUnitDatabaseConfig());
return databaseDataSourceConnectionFactoryBean;
}
}
将 qualifiedTableNames 设置为 true 后,您应该在 xml
中为您的 table 提供全名
<public.user id="1" created_date='2017-01-01 00:00:00' email="root@demo.io" password="your password" username="root"/>
<dataset>
<user id="1" created_date='2017-01-01 00:00:00' email="" user_name="root"/>
</dataset>
xml 上面给了我错误。问题是我为用户保留了字。我该如何解决这个问题。有链接吗?
已更新
我正在使用 spring 引导,spring 数据 jpa,spring-test-dbunit,dbunit,postgresql
根据此论坛 https://sourceforge.net/p/dbunit/mailman/message/20643023/ DBUnit 似乎没有办法“引用”table 名称。但是,如果您出于某种原因不想重命名 table 或使用遗留数据库
,则可以配置DatabaseDataSourceConnectionFactoryBean
@Configuration
public class Custom.... {
@Autowired
private DataSource dataSource;
@Bean
public DatabaseConfigBean dbUnitDatabaseConfig() {
DatabaseConfigBean dbConfigBean = new DatabaseConfigBean();
// dbConfigBean.setDatatypeFactory(new PostgresqlDataTypeFactory());
dbConfigBean.setQualifiedTableNames(true);
return dbConfigBean;
}
@Bean
public DatabaseDataSourceConnectionFactoryBean dbUnitDatabaseConnection() {
DatabaseDataSourceConnectionFactoryBean databaseDataSourceConnectionFactoryBean = new DatabaseDataSourceConnectionFactoryBean(dataSource);
databaseDataSourceConnectionFactoryBean.setDatabaseConfig(dbUnitDatabaseConfig());
return databaseDataSourceConnectionFactoryBean;
}
}
将 qualifiedTableNames 设置为 true 后,您应该在 xml
中为您的 table 提供全名<public.user id="1" created_date='2017-01-01 00:00:00' email="root@demo.io" password="your password" username="root"/>