用Ibatis联接数据库。
ibatis2.3.jar;
sql2000;
myeclipse7.0
问题描述:
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>
<properties resource="jdbc.properties" />
<settings
cacheModelsEnabled="true"
enhancementEnabled="true"
lazyLoadingEnabled="true"
maxRequests="32"
maxSessions="10"
maxTransactions="5"
useStatementNamespaces="false"
/>
<typeAlias alias="person" type="com.ecp.ibatis.java.Person" />
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${jdbc.driver}" />
<property name="JDBC.ConnectionURL" value="${jdbc.url}" />
<property name="JDBC.Username" value="${jdbc.user}" />
<property name="JDBC.Password" value="${jdbc.password}" />
</dataSource>
</transactionManager>
<sqlMap resource="com/ecp/ibatis/map/Person_SqlMap.xml" />
</sqlMapConfig>
person_SqlMap.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Person">
<resultMap id="person" class="com.ecp.ibatis.java.Person">
<!--
WARNING - This element is automatically generated by Abator for iBATIS, do not modify.
This element was generated on Fri Mar 20 15:38:16 CST 2009.
-->
<result column="PER_ID" property="perId" jdbcType="NUMERIC"/>
<result column="PER_FIRSTNAME" property="perFirstname" jdbcType="VARCHAR"/>
<result column="PER_LASTNAME" property="perLastname" jdbcType="VARCHAR"/>
<result column="PER_BIRTHDAY" property="perBirthday" jdbcType="TIMESTAMP"/>
<result column="PER_WEIGTH_KG" property="perWeigthKg" jdbcType="NUMERIC"/>
<result column="PER_HEIGHT_M" property="perHeightM" jdbcType="NUMERIC"/>
</resultMap>
<select id="getPerson" resultMap="person" parameterClass="java.lang.Integer">
<!--
WARNING - This element is automatically generated by Abator for iBATIS, do not modify.
This element was generated on Fri Mar 20 15:38:16 CST 2009.
-->
select PER_ID, PER_FIRSTNAME, PER_LASTNAME, PER_BIRTHDAY, PER_WEIGTH_KG, PER_HEIGHT_M
from Person
where PER_ID = #perId:NUMERIC#
</select>
</sqlMap>
别外有一个 Person.java
一些SET,GET属性
jdbc.properties
jdbc.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
jdbc.url=jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=ecp
jdbc.user=sa
jdbc.password=123456
联接数据库时,报出以下异常。
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/ecp/ibatis/map/Person_SqlMap.xml.
--- The error occurred while applying a result map.
--- Check the Person.person.
--- The error happened while setting a property on the result object.
--- Cause: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:185)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java:104)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:566)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:541)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:83)
at com.ecp.ibatis.main.Test.main(Test.java:21)
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseImplDatabaseMetaData.getImplConnection(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplDatabaseMetaData.processServerInfo(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplDatabaseMetaData.initializeNonResultSetMetaData(Unknown Source)
at com.microsoft.jdbc.base.BaseDatabaseMetaData.supportsMultipleResultSets(Unknown Source)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.moveToNextResultsSafely(SqlExecutor.java:354)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:326)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:190)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
... 6 more
Exception in thread "main"
通过搜索网上各位的解决方法。
参考请见
http://blog.csdn.net/sunyujia/archive/2008/07/13/2646030.aspx
改动
jdbc.properties
中的.url
jdbc.url=jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=ecp
变为
jdbc.url=jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=ecp;selectMethod=cursor