问题描述
我使用Mssql和Spring Batch。我需要与同一数据库中的两个架构进行交互。但是,驱动程序由于某种原因会忽略该方案的安装,而是使用标准方案之一。我该如何解决?
@Bean
public DataSource targetDataSource() {
SimpleDriverDataSource dataSource = getSimpleDriverDataSource();
dataSource.setSchema("target");
return dataSource;
}
@Bean
public DataSource sourceDataSource() {
SimpleDriverDataSource dataSource = getSimpleDriverDataSource();
dataSource.setSchema("source");
return dataSource;
}
private SimpleDriverDataSource getSimpleDriverDataSource() {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setDriverClass(com.microsoft.sqlserver.jdbc.sqlServerDriver.class);
dataSource.setUsername("sa");
dataSource.setUrl("jdbc:sqlserver://localhost:1433;database=myDB");
dataSource.setPassword("myPassword");
return dataSource;
}
缠绕代码:
@Bean
public JdbcBatchItemWriter<Person> writer() {
return new JdbcBatchItemWriterBuilder<Person>()
.itemsqlParameterSourceProvider(new BeanPropertyItemsqlParameterSourceProvider<>())
.sql("INSERT INTO target.people (first_name,last_name) VALUES (:firstName,:lastName)") //Todo убрать схему
.dataSource(targetDataSource())
.build();
}
删除target.
部分时,将出现PreparedStatement Callback exception; bad sql grammar [INSERT INTO people (first_name,last_name) VALUES (?,?)]; nested exception is java.sql.BatchUpdateException: Invalid object name 'people'.
,从架构中读取时也会发生同样的情况。从请求中删除架构名称后,我立即收到异常
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)