gpt4 book ai didi

spring - PreparedStatementCallback;错误的 SQL 语法 [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ?和 JOB_KEY =?

转载 作者:行者123 更新时间:2023-12-04 15:46:52 24 4
gpt4 key购买 nike

我想要 Spring Batch 元数据 在 MySQL 服务器上创建并使用所有来自 Oracle 的现有表从中获取数据并将其放入 MongoDB。

我创建了以下配置,但不知何故错过了通过配置创建 Spring Batch 元数据表的技巧。

spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=MY_DB

#By default, Spring runs all the job as soon as it has started its context.
spring.batch.job.enabled=false

spring.batch.initialize-schema=always
spring.batch.tablePrefix=test.BATCH_
#spring.batch.initializer.enabled=false
spring.batch.schema=org/springframework/batch/core/schema-mysql.sql

spring.datasource.url=jdbc:oracle:thin:@localhost:1527:OR_DEV
spring.datasource.username=EDR_USR
spring.datasource.password=txz$2Zhr
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

jdbc.batch.jdbcUrl=jdbc:mysql://localhost:3306/test?useSSL=false
jdbc.batch.username=root
jdbc.batch.password=root
jdbc.batch.driver-class-name=com.mysql.cj.jdbc.Driver

数据库配置文件
@Configuration
@ComponentScan
public class DBConfig {

@Autowired
private Environment env;

@Bean(name="oracleDS")
public DataSource batchDataSource(){
return DataSourceBuilder.create()
.url(env.getProperty("spring.datasource.url"))
.driverClassName(env.getProperty("spring.datasource.driver-class-name"))
.username(env.getProperty("spring.datasource.username"))
.password(env.getProperty("spring.datasource.password"))
.build();
}

@Bean(name="mysqlDS")
@Primary
public DataSource mysqlBatchDataSource(){
return DataSourceBuilder.create()
.url(env.getProperty("jdbc.batch.jdbcUrl"))
.driverClassName(env.getProperty("jdbc.batch.driver-class-name"))
.username(env.getProperty("jdbc.batch.username"))
.password(env.getProperty("jdbc.batch.password"))
.build();
}
}

工作
@GetMapping("/save-student")
public String saveStudent() {
JobParameters params = new JobParametersBuilder()
.addString("JobID", String.valueOf(System.currentTimeMillis()))
.addString("Job_ID", String.valueOf(System.currentTimeMillis()))
.addDate("date", new Date())
.toJobParameters();
try {
JobExecution jobExecution = jobLauncher.run(countryJob, params);
log.debug("Job Status : " + jobExecution.getStatus());
} catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException
| JobParametersInvalidException e) {
log.error("Job Failed : "+e.getMessage());
}
return "";
}

错误:
{
"timestamp": "2019-03-27T14:57:52.745+0000",
"status": 500,
"error": "Internal Server Error",
"message": "PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?]; nested exception is java.sql.SQLSyntaxErrorException: Table 'test.batch_job_instance' doesn't exist",
"path": "/save-student"
}

最佳答案

为了解决这个问题,我通过从这里执行脚本来手动执行 MYSQL spring 批处理元数据表:MySQL Spring Batch Metadata tables script

由于我们有两个数据源,Spring Batch 无法自动创建元数据表,因此会出现此错误。我手动执行脚本作为解决方法,但是有什么办法可以通过代码解决这个问题吗?

关于spring - PreparedStatementCallback;错误的 SQL 语法 [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ?和 JOB_KEY =?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55381505/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com