java - Check if database is available before job in spring batch -
my question how check if database available before starting job in spring batch.
i tried create new class implements jobexecutionlistener
, , call method beforejob
. problem how test, because database configuration in database-context.xml
?
database-context.xml:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:batch="http://www.springframework.org/schema/batch" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd"> <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="com.mysql.jdbc.driver" /> <property name="url" value="jdbc:mysql://localhost:3306/mydb_3" /> <property name="username" value="root" /> <property name="password" value="" /> </bean> </beans>
for example, when put mydb_4
(and mydb_4
doesn't exist), following error:
error while extracting database product name - falling empty error codes org.springframework.jdbc.support.metadataaccessexception: not connection extracting meta data; nested exception org.springframework.jdbc.cannotgetjdbcconnectionexception: not jdbc connection; nested exception com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: unknown database 'mydb_4' @ org.springframework.jdbc.support.jdbcutils.extractdatabasemetadata(jdbcutils.java:293)
now how catch error , check if database available in method created in beforejob
?
Comments
Post a Comment