论坛首页 Java企业应用论坛

请教ibatis运行异常

浏览 3858 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-12-04  
日志:
2007-12-03 21:06:47,828 INFO [lsjGui.JinRu] - com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in lsjDomain/Js.xml. 
--- The error occurred while applying a result map. 
--- Check the Js.RMJs. 
--- 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.

代码:
lsjGui/JinRu.java
...
         private static final Logger log = Logger.getLogger(JinRu.class);

	private static SqlMapClient sqlMapper;
	static {
		try {
			Reader reader = Resources
					.getResourceAsReader("lsjDomain/SqlMapConfig.xml");
			sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
			reader.close();
		} catch (IOException e) {
			throw new RuntimeException(
					"Something bad happened while building the SqlMapClient instance."
							+ e, e);
		}
	}

	public void zb() {
try {
			sqlMapper.startTransaction();
			List js = sqlMapper.queryForList("queryAll");
			sqlMapper.commitTransaction();
		} catch (Exception e) {
			log.info(e.toString());
			System.exit(0);
		} finally {
			try {
			sqlMapper.endTransaction();
			}
			catch (Exception e) {
				log.info(e.toString());
				System.exit(0);
			}
		}


====================
lsjDomain/SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMapConfig      
    PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"      
    "http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
	<transactionManager type="JDBC" commitRequired="false">
		<dataSource type="SIMPLE">
			<property name="JDBC.Driver"
				value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
			<property name="JDBC.ConnectionURL"
				value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=EMIS" />
			<property name="JDBC.Username" value="sa" />
			<property name="JDBC.Password" value="" />			
		</dataSource>
	</transactionManager>

	<sqlMap resource="lsjDomain/Js.xml" />


</sqlMapConfig>



========
lsjDomain/Js.java
package lsjDomain;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class Js {
	public Integer c0;
	public String c1;
	public Integer getC0() {
		return c0;
	}
	public void setC0(int c0) {
		this.c0 = c0;
	}
	public String getC1() {
		return c1;
	}
	public void setC1(String c1) {
		this.c1 = c1;
	}
	public String toString() {
		return "c0 = "+c0+ " , c1 = "+c1;
	}
}


========
lsjDomain/Js.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="Js">
	<typeAlias alias="js" type="lsjDomain.Js" />
	<resultMap class="js" id="RMJs">
		<result property="c0" column="c0" />
		<result property="c1" column="c1" />
	</resultMap>
	<select id="queryAll" resultMap="RMJs">
		select c0, c1 from emis_1
	</select>
</sqlMap>

   发表时间:2007-12-04  
这是SQL Server抛出来的错误, 和iBatis无关。

因为你用手动模式的事务再加上默认的direct (SelectMethod=direct) mode, 多次请求执行SQL Server就会出现这个错误。

下面代码可以重现你的错误。

import java.sql.*;
import java.io.*;


public class Repro{

	public static void main(String args[])
	{
		try {
			Connection con;
			Statement s1 = null;
			ResultSet r1 = null;
			Statement s2 = null;
			ResultSet r2 = null;
			Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); 
			con = DriverManager.getConnection(
				"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs;SelectMethod=Direct;User=User;Password=Password");
			//fix 1
				//"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs;SelectMethod=Cursor;User=User;Password=Password");
			con.setAutoCommit(false);
			
			try {
				s1 = con.createStatement();
				r1 = s1.executeQuery("SELECT * FROM authors");
				
				//fix 2
				//r1.close();
				//s1.close();

				s2 = con.createStatement();
				r2 = s2.executeQuery("SELECT * FROM publishers");
			}
			catch (SQLException ex)
			{
				System.out.println(ex);				
			}
		
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}



0 请登录后投票
   发表时间:2007-12-04  
谢谢

请问如何改 lsjGui/JinRu.java ,或者能给个案例


0 请登录后投票
   发表时间:2007-12-05  
select studentID,classStageID,enterDate,classID,endDate from edu_studentStageTime where studentID=#studentID:VARCHAR# and classStageID =#classStageID:VARCHAR#
0 请登录后投票
   发表时间:2007-12-05  
select studentID,classStageID,enterDate,classID,endDate from edu_studentStageTime where studentID=#studentID:VARCHAR# and classStageID =#classStageID:VARCHAR#
0 请登录后投票
   发表时间:2007-12-05  
谢谢,是这个吧

<select parameterclass="java.util.HashMap" resultclass="org.haiter.edu.base.student.StudentStageTime" id="getByID">
		select studentID,classStageID,enterDate,classID,endDate
		 from edu_studentStageTime
		 where  studentID=#studentID:VARCHAR# and classStageID =#classStageID:VARCHAR#
	</select>



我明天试试
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics