我使用了preparedstatement来执行一段sql,用callablestatement来执行一个存储,会建立两个connection,放在一个事务处理中,可以吗?

解决方案 »

  1.   

    为什么会存在两个Connection,应该来说这个preparedstatement和callablestatement应该是在开始事务之后由这个Connection创建的如果是这样做,则当然是同一个事务中
    如果你使用了两个连接,则除非你使用XA事务,否则他们不在同一个事务中
      

  2.   

    如果对一个数据库, 用一个Connection好了, 做preparedstatement和callablestatement如果多个数据库, 要不用XA事务, 要不用两阶段提交
      

  3.   

    完全可以用一个connection来处理呀,为什么要两个呢!
      

  4.   

    Can't start a cloned connection while in manual transaction mode.  我在使用一个connection的时候,出现这个问题,请教高手。
      

  5.   

    我个人觉得建立2个连接,一般产成在需要嵌套的地方。比如说:在select一个结果集后,在取这个结果集中数据的时候又要SELECT了,这时这个SELECT需要用第二个连接,否则会出错的。但这样的危险性比较高,比较好的办法是把第一个结果集全取出来放在LIST中,然后循环LIST时再进行第二个SELECT。
      

  6.   

    SYMPTOMS
    While using the Microsoft SQL Server 2000 Driver for JDBC, you may experience the following exception:java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode. CAUSE
    This error occurs when you try to execute multiple statements against a SQL Server database with the JDBC driver while in manual transaction mode (AutoCommit=false) and while using the direct (SelectMethod=direct) mode. Direct mode is the default mode for the driver. 
    RESOLUTION
    When you use manual transaction mode, you must set the SelectMethod property of the driver to Cursor, or make sure that you use only one active statement on each connection as specified in the "More Information" section of this article. 
      

  7.   

    如果你使用SQL Server,我记得好像是可以在连接字符串后面加上 SelectMethod=cursor来解决这个问题