issue with jdbcItemReader DB2 driver
kk31 Oct 3, 2016 1:41 PMHi,
I am trying to develop standalone java batch application which reads data from DB2(v9.7) tables and writes it to csv file with out header with JDK 1.8.
In jberet.properties , i have the following setup.
job-repository-type = jdbc
db-url = jdbc:db2://xxx:123/schemaName
db-user = xxxx
db-password = xxxx
In job.xml, i have the following configuration.
<reader ref="jdbcItemReader">
<properties>
<property name="sql" value=" />
<property name="driver-name" value="com.ibm.db2.jcc.DB2Driver" />
<property name="url" value="jdbc:db2://xxx:123/schemaName" />
<property name="user" value="xxxx" />
<property name="password" value="xxxx" />
<property name="beanType" value="java.util.List" />
</properties>
</reader>
In my classpath, i set db2jcc.jar which is JDBC 3 complaint jar, and i am getting the following error message
Caused by: java.sql.SQLException: No suitable driver found forjdbc:db2://xxx:123/schemaName
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at org.jberet.repository.JdbcRepository.getConnection(JdbcRepository.java:976)
... 17 more
If i add db2jcc4.jar which is JDBC 4 complaint jar, it is happy and able to read the messages from tables.
I also observed that the order of these two jar files are important. Correct order is db2Jcc.jar followed by db2JCC4.jar. If I change the order in the classpath, it throws the following exception.
Exception in thread "main" javax.batch.operations.BatchRuntimeException: JBERET000626: Failed to run INSERT INTO JOB_INSTANCE(JOBNAME, APPLICATIONNAME) VALUES(?, ?)
at org.jberet.repository.JdbcRepository.insertJobInstance(JdbcRepository.java:326)
at org.jberet.repository.AbstractPersistentRepository.createJobInstance(AbstractPersistentRepository.java:105)
at org.jberet.operations.JobOperatorImpl$2.invoke(JobOperatorImpl.java:127)
at org.jberet.operations.JobOperatorImpl$2.invoke(JobOperatorImpl.java:124)
at org.jberet.operations.JobOperatorImpl.invokeTransaction(JobOperatorImpl.java:402)
at org.jberet.operations.JobOperatorImpl.start(JobOperatorImpl.java:124)
at org.jberet.operations.JobOperatorImpl.start(JobOperatorImpl.java:104)
Caused by: com.ibm.db2.jcc.am.SqlException: [jcc][10120][11803][4.7.85] Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null
at com.ibm.db2.jcc.am.dd.a(dd.java:660)
at com.ibm.db2.jcc.am.dd.a(dd.java:60)
at com.ibm.db2.jcc.am.dd.a(dd.java:103)
at com.ibm.db2.jcc.am.fb.b(fb.java:1259)
at com.ibm.db2.jcc.am.fb.b(fb.java:1284)
at com.ibm.db2.jcc.am.fb.getLong(fb.java:476)
at org.jberet.repository.JdbcRepository.insertJobInstance(JdbcRepository.java:323)
... 8 more
So question is why do we need to have two jar files in classpath with correct order?
Thanks,
KK.