Hi,
I noticed that the website now recommends using the spring dao framework
instead of the ibatis one.
I have never used spring before and decided to try a little test to see how
to get the spring dao
framework up and running with ibatis. I am using spring 2.01 and have tried
ibatis 2.1.7.597,
2.2.0.638 and 2.3.0.677 but still get the following error. According to the
log it looks like
an ">" is getting inserted into my sql statement somewhere in the process.
Is there something in my
spring files that is causing this? Any ideas?
Thanks,
Cory
.
error -
2006-12-13 08:38:40,551 INFO [org.springframework.core.CollectionFactory] -
<JDK 1.4+ collections available>
2006-12-13 08:38:40,598 INFO
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading
XML bean definitions from class path resource [beans.xml]>
2006-12-13 08:38:41,804 DEBUG [java.sql.Connection] - <{conn-100000}
Connection>
2006-12-13 08:38:42,039 DEBUG [java.sql.PreparedStatement] - <{pstm-100001}
PreparedStatement: SELECT * FROM OTOT_JOB_SCHEDULE >
2006-12-13 08:38:42,039 DEBUG [java.sql.PreparedStatement] - <{pstm-100001}
Parameters: []>
2006-12-13 08:38:42,039 DEBUG [java.sql.PreparedStatement] - <{pstm-100001}
Types: []>
2006-12-13 08:38:42,071 INFO
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading
XML bean definitions from class path resource
[org/springframework/jdbc/support/sql-error-codes.xml]>
2006-12-13 08:38:42,180 INFO
[org.springframework.jdbc.support.SQLErrorCodesFactory] - <SQLErrorCodes
loaded: [DB2, Derby, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL,
Sybase]>
Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException:
SqlMapClient operation; bad SQL grammar []; nested exception is
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in test/OtotJobSchedule.xml.
--- The error occurred while applying a parameter map.
--- Check the OtotJobSchedule.getAll-InlineParameterMap.
--- Check the statement (query failed).
--- Cause: java.sql.SQLException: ORA-00942: table or view does not exist
beans.xml -
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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="ototJobScheduleDao" class="test.SqlMapOtotJobScheduleDao">
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
<bean id="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:@hostname:1521:sid" />
<property name="username" value="username" />
<property name="password" value="password" />
</bean>
<bean id="sqlMapClient" class=
"org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="test/sql-map-config.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>
sql-map-config.xml -
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<settings
useStatementNamespaces="true"
cacheModelsEnabled="true"
enhancementEnabled="true"/>
<sqlMap resource="test/OtotJobSchedule.xml" />
</sqlMapConfig>
OtotJobSchedule.xml -
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="OtotJobSchedule">
<resultMap id="result" class="test.OtotJobSchedule">
<result property="id" column="ID" columnIndex="1"/>
<result property="description" column="DESCRIPTION" columnIndex="2"/>
<result property="cron" column="CRON" columnIndex="3"/>
<result property="jobType" column="JOB_TYPE" columnIndex="4"/>
<result property="param" column="PARAM" columnIndex="5"/>
<result property="active" column="ACTIVE" columnIndex="6"/>
</resultMap>
<select id="getAll" resultMap="result">
SELECT * FROM OTOT_JOB_SCHEDULE
</select>
</sqlMap>
Main.java -
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Iterator;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import test.OtotJobSchedule;
import test.OtotJobScheduleDao;
public class Main {
public static void main(String[] args) {
ClassPathResource resource = new ClassPathResource("beans.xml");
BeanFactory beanFactory = new XmlBeanFactory(resource);
OtotJobScheduleDao ototJobScheduleDao = (OtotJobScheduleDao)
beanFactory
.getBean("ototJobScheduleDao");
List list = ototJobScheduleDao.getAll();
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
OtotJobSchedule ototJobSchedule = (OtotJobSchedule) iterator.next();
System.out.println(ototJobSchedule.getId() + ":"
+ ototJobSchedule.getDescription() + ":"
+ ototJobSchedule.getJobType());
}
}
}
Cory Bestgen
Information Technology Division
Office of State Courts Administrator
(573) 522 - 5455
[EMAIL PROTECTED]