recherche

Maison  >  Questions et réponses  >  le corps du texte

java - 关闭数据库连接之前为什么要先设置自动提交为true?

伊谢尔伦伊谢尔伦2811 Il y a quelques jours837

répondre à tous(1)je répondrai

  • ringa_lee

    ringa_lee2017-04-18 10:08:03

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    <code>

        protected void resetAutoCommit() {

            try {

              if (!connection.getAutoCommit()) {

                // MyBatis does not call commit/rollback on a connection if just selects were performed.

                // Some databases start transactions with select statements

                // and they mandate a commit/rollback before closing the connection.

                // A workaround is setting the autocommit to true before closing the connection.

                // Sybase throws an exception here.

                if (log.isDebugEnabled()) {

                  log.debug("Resetting autocommit to true on JDBC Connection [" + connection + "]");

                }

                connection.setAutoCommit(true);

              }

            } catch (SQLException e) {

              log.debug("Error resetting autocommit to true "

                  + "before closing the connection.  Cause: " + e);

            }

          }

    </code>

    C'est clairement indiqué dans le code. Cette note.

    répondre
    0
  • Annulerrépondre