Could not open JDBC Connection for transaction java.sql.SQLException: ORA-00923:
Hi,
I need to read the contect from csv file and need insert in to oracle database. I got that exact link(http://www.ecomputercoach.com), but while running that example its throwing error. can any body help on this....the error is...
ERROR - Job Terminated in error:
org.springframework.transaction.CannotCreateTransa ctionException: Could not open JDBC Connection for transaction; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ORA-00923: FROM keyword not found where expected
)
at org.springframework.jdbc.datasource.DataSourceTran sactionManager.doBegin(DataSourceTransactionManage r.java:238)
at org.springframework.transaction.support.AbstractPl atformTransactionManager.getTransaction(AbstractPl atformTransactionManager.java:374)
at org.springframework.transaction.interceptor.Transa ctionAspectSupport.createTransactionIfNecessary(Tr ansactionAspectSupport.java:263)
at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:101)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy0.getLastJobExecution(Unknown Source)
at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:85)
at org.springframework.batch.core.launch.support.Comm andLineJobRunner.start(CommandLineJobRunner.java:2 07)
at org.springframework.batch.core.launch.support.Comm andLineJobRunner.main(CommandLineJobRunner.java:25 4)
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (ORA-00923: FROM keyword not found where expected
)
at org.apache.commons.dbcp.BasicDataSource.createData Source(BasicDataSource.java:1244)
at org.apache.commons.dbcp.BasicDataSource.getConnect ion(BasicDataSource.java:882)
at org.springframework.jdbc.datasource.DataSourceTran sactionManager.doBegin(DataSourceTransactionManage r.java:200)
... 9 more
Caused by: java.sql.SQLException: ORA-00923: FROM keyword not found where expected
at oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoe r.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoe r.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java: 745)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStateme nt.java:207)
at oracle.jdbc.driver.T4CStatement.executeForDescribe (T4CStatement.java:801)
at oracle.jdbc.driver.OracleStatement.executeMaybeDes cribe(OracleStatement.java:1039)
at oracle.jdbc.driver.T4CStatement.executeMaybeDescri be(T4CStatement.java:841)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTi meout(OracleStatement.java:1134)
at oracle.jdbc.driver.OracleStatement.executeQuery(Or acleStatement.java:1274)
at org.apache.commons.dbcp.DelegatingStatement.execut eQuery(DelegatingStatement.java:208)
at org.apache.commons.dbcp.PoolableConnectionFactory. validateConnection(PoolableConnectionFactory.java: 332)
at org.apache.commons.dbcp.BasicDataSource.validateCo nnectionFactory(BasicDataSource.java:1268)
at org.apache.commons.dbcp.BasicDataSource.createData Source(BasicDataSource.java:1240)
... 11 more
here are the files..........what i am using and facing problem
DB-JOBREPOSITORY.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
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-2.0.xsd">
<bean id="jobRepository-dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@10.106.65.159:1531:eba" />
<property name="username" value="xxxxx" /> <!-- your user id. e.g. root-->
<property name="password" value="xxxxx" /> <!-- your password-->
<property name="maxIdle" value="10"/>
<property name="maxActive" value="100"/>
<property name="maxWait" value="10000"/>
<property name="validationQuery" value="select 1"/>
<property name="testOnBorrow" value="false"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="1200000"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
<property name="numTestsPerEvictionRun" value="5"/>
<property name="defaultAutoCommit" value="false"/>
</bean>
<bean id="jobRepository-transactionManager"
class="org.springframework.jdbc.datasource.DataSou rceTransactionManager" lazy-init="true">
<property name="dataSource" ref="jobRepository-dataSource" />
</bean>
<bean id="jobRepository"
class="org.springframework.batch.core.repository.s upport.JobRepositoryFactoryBean">
<property name="dataSource" ref="jobRepository-dataSource" />
<property name="transactionManager" ref="jobRepository-transactionManager"/>
<property name="databaseType" value="oracle" />
<property name="tablePrefix" value="batch_"/>
</bean>
<bean id="asyncTaskExecutor"
class="org.springframework.core.task.SimpleAsyncTa skExecutor"/>
<bean id="syncTaskExecutor"
class="org.springframework.core.task.SyncTaskExecu tor" />
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.suppo rt.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository"/>
</bean>
<bean id="jobExplorer"
class="org.springframework.batch.core.explore.supp ort.JobExplorerFactoryBean"
p:dataSource-ref="jobRepository-dataSource" p:tablePrefix="batch_" />
</beans>
ApplicationDB.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
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-2.0.xsd">
<bean id="test-dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@10.106.65.159:1531:eba" />
<property name="username" value="xxxxxx" />
<property name="password" value="xxxxxxx" />
<property name="maxIdle" value="10"/>
<property name="maxActive" value="100"/>
<property name="maxWait" value="10000"/>
<property name="validationQuery" value="select 1"/>
<property name="testOnBorrow" value="false"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="1200000"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
<property name="numTestsPerEvictionRun" value="5"/>
<property name="defaultAutoCommit" value="true"/>
</bean>
<bean id="testDB-transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager" lazy-init="true">
<property name="dataSource" ref="test-dataSource" />
</bean>
</beans>
FileToTableJob.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schem...-beans-2.0.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schem...-batch-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schem...ng-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!--<import resource="MEMORY-JOBREPOSITORY.xml"/> -->
<import resource="DB-JOBREPOSITORY.xml"/>
<import resource="ApplicationDB.xml"/>
<bean id="playerFileItemReader" class="org.springframework.batch.item.file.FlatFil eItemReader">
<!-- <property name="resource" value="classpath:input/player.csv" /> -->
<property name="resource" value="file:e:\player.csv" />
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping .DefaultLineMapper">
<property name="lineTokenizer">
<bean class="org.springframework.batch.item.file.transfo rm.DelimitedLineTokenizer">
<property name="delimiter" value=","/>
<property name="names" value="ID,lastName,firstName,position,debutYear,fi nalYear" />
</bean>
</property>
<property name="fieldSetMapper">
<bean class="PlayerFieldSetMapper" />
</property>
</bean>
</property>
</bean>
<bean id="careerProcessor" class="CareerProcessor" />
<bean id="playerDBWriter" class="org.springframework.batch.item.database.Jdb cBatchItemWriter">
<property name="assertUpdates" value="false" />
<property name="itemSqlParameterSourceProvider">
<bean name="sqlParameterSourceProvider" id="sqlParameterSourceProvider" class="org.springframework.batch.item.database.Bea nPropertyItemSqlParameterSourceProvider" />
</property>
<property name="sql" value="insert into PLAYER (PLAYER_ID, FIRST_NAME, LAST_NAME, POSITION, DEBUT_YEAR, FINAL_YEAR,CAREER_LENGTH) values (:id, :lastName , :firstName , :position , :debutYear ,:finalYear, :careerLength)"/>
<property name="dataSource" ref="test-dataSource" />
</bean>
<bean id="dynamicJobParameters" class="DynamicJobParameters" />
<batch:job id="careerProcessorJob" job-repository="jobRepository" incrementer="dynamicJobParameters">
<batch:step id="step1">
<batch:tasklet transaction-manager="jobRepository-transactionManager" >
<batch:chunk reader="playerFileItemReader" processor="careerProcessor" writer="playerDBWriter" commit-interval="10" />
</batch:tasklet>
</batch:step>
</batch:job>
</beans>
table or view does not exist
Hi Rams,
the error says that Spring-Batch cannot find the table "batch_JOB_INSTANCE" in your oracle database.
Maybe you forgot to create the tables in you schema (try looking at "schema-oracle10g.sql") or maybe the table was created in a different schema and you forgot to create synonyms? Maybe there are missing rights?
Try creating a session with your oracle database outside of spring, but by using the same connection settings, and test if the following select works: "SELECT JOB_INSTANCE_ID, JOB_NAME from batch_JOB_INSTANCE". Work from there!
Best wishes,
Robin