Can't start a cloned connection while in manual transaction mode.错误的解决方案

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.BaseStatement.setupImplConnection(Unknown Source)
 at com.microsoft.jdbc.base.BaseStatement.<init>(Unknown Source)
 at com.microsoft.jdbc.base.BasePreparedStatement.<init>(Unknown Source)
 at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Source)
 at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Source)
 at com.capitel.telecom.tobacco.dao.TightsmokeDAO.insertTightsmokeInfo(TightsmokeDAO.java:57)
 at com.capitel.telecom.tobacco.logic.DataMaintainManager.tightsmokeAdd(DataMaintainManager.java:616)

。。。。。。。。。。

 

上面是从mysql数据库升级到SQL Server数据库时,第一次报的错误

从网上找了一些解决方案,先PS在下面:

--------------------------------------------------------------------------------------------------------------------------------
解决方案:(1)

你在尝试打开一个克隆连接,有两种解决办法: 每个数据库的连接在执行完毕后,关闭,第二,在连接时,判断是否已经有连接存在,有则使用现成的连接。 数据库连接可以设置成一个常量,不需要到处定义。便于维护。

解决方案:(2)

你在DatabaseURL字符串中加入SelectMethod=Cursor;如下
jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=Partner;SelectMethod=Cursor;

 

--------------------------------------------------------------------------------------------------------------------------------

If you pass "SelectMethod=cursor" attribute in connectio url, will allow more than one active statement per connection." jdbc:microsoft:sqlserver://localhost:1433;SelectMethod=cursor;","user","pwd"The reason for this is;When SelectMethod is set to direct, SQL Server does not support multiple active statements on a single connection within a transaction; however, when auto-commit mode is enabled (the default), the Microsoft SQL Server JDBC driver provides the ability to have multiple JDBC statements open on a single JDBC connection. This is done by cloning physical SQL Server connections as needed. To avoid cloning physical SQL Server connections in this circumstance, you should create only one Statement, PreparedStatement, CallableStatement, or DatabaseMetaData object per JDBC Connection
object. Be sure to invoke the "close" methods on these objects when you are finished with them, that is, before creating another object of the types described.Sridhar PaladuguMicrosoft Developer SupportJDBC Webdata

 

--------------------------------------------------------------------------------------------------------------------------------
是因为commit设置为false了,查资料,对URL做修改:jdbc:microsoft:sqlserver://localhost:1433;user=test;password=secret;SelectMethod=cursor;问题解决。

 

 

---------------------------------------------感觉比较有理由的下面的这个说法------------------------------------------------
原因一般是当你在一个SQL SERVER的JDBC连接上执行多个STATEMENTS的操作,或者是手动事务状态(AutoCommit=false) 并且使用默认的模式. direct (SelectMethod=direct) 模式.

解决办法
当你使用手动事务模式时,必须把SelectMethod 属性的值设置为 Cursor, 或者是确保在你的连接只有一个STATEMENT操作。

修改url

加入SelectMethod=cursor即可

 

总结一下:

    我也只在连接数据库的URL后面添加了一段SelectMethod=cursor;就可以正常使用了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值