{"id":23,"date":"2013-03-07T15:28:24","date_gmt":"2013-03-07T15:28:24","guid":{"rendered":"http:\/\/www.yeetrack.com\/post\/2013-03-07\/mysql%E6%95%B0%E6%8D%AE%E5%BA%93%E4%BA%8B%E5%8A%A1%E6%93%8D%E4%BD%9C"},"modified":"2013-09-27T22:36:53","modified_gmt":"2013-09-27T14:36:53","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e4%ba%8b%e5%8a%a1%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=23","title":{"rendered":"mysql\u6570\u636e\u5e93\u4e8b\u52a1\u64cd\u4f5c"},"content":{"rendered":"<p>\u6570\u636e\u5e93\u4e2d\u7684\u4e8b\u52a1\u5c31\u662f\u4e00\u4e2a\u4e8b\u52a1\u4e2d\u7684\u64cd\u4f5c\u8981\u4e48\u4e00\u8d77\u6210\u529f,\u8981\u4e48\u4e00\u8d77\u5931\u8d25\uff0c\u4e8b\u52a1\u672c\u8eab\u5177\u6709\u539f\u5b50\u6027\u3001\u4e00\u81f4\u6027\u3001\u9694\u79bb\u6027\u548c\u6301\u4e45\u6027\u3002<\/p>\n<ul class=\"edui-filter-disc\">\n<li>\n<p>SET AUTOCOMMIT = 0; &nbsp;\/\/\u53d6\u6d88\u81ea\u52a8\u63d0\u4ea4\uff0c\u5f00\u59cb\u4e8b\u52a1\u5904\u7406<\/p>\n<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<ul class=\"edui-filter-disc\">\n<li>\n<p>SET AUTOCOMMIT = 1; &nbsp;\/\/\u5f00\u542f\u81ea\u52a8\u63d0\u4ea4\uff0c\u5173\u95ed\u4e8b\u52a1\u5904\u7406<\/p>\n<\/li>\n<li>\n<p>START TRANSACTION; &nbsp;\/\/\u542f\u52a8\u4e8b\u52a1<\/p>\n<\/li>\n<li>\n<p>BEGIN \u542f\u52a8\u4e8b\u52a1\uff0c\u76f8\u5f53\u4e8eSTART TRANSACTION<\/p>\n<\/li>\n<li>\n<p>COMMIT \u63d0\u4ea4\u4e8b\u52a1<\/p>\n<\/li>\n<li>\n<p>ROLLBACK \u56de\u6eda\u5168\u90e8\u64cd\u4f5c<\/p>\n<\/li>\n<li>\n<p>SAVEPOINT \u8bbe\u7f6e\u4e8b\u52a1\u4fdd\u5b58\u70b9<\/p>\n<\/li>\n<li>\n<p>POLLBACK TO SAVEPOINT \u56de\u6eda\u64cd\u4f5c\u5230\u4fdd\u5b58\u70b9<\/p>\n<\/li>\n<\/ul>\n<p>\u4e0a\u9762\u7684\u547d\u4ee4\u90fd\u662f\u57fa\u4e8esession\u7684\uff0c\u6570\u636e\u5e93\u628a\u6bcf\u4e00\u4e2a\u8fde\u63a5\u5230\u6570\u636e\u5e93\u7684\u7528\u6237\u770b\u4f5c\u4e00\u4e2asession\u3002\u4e0b\u9762\u662f\u6570\u636e\u5e93\u4e8b\u52a1\u63d0\u4ea4\u7684\u4e00\u4e2a\u7b80\u5355\u4f8b\u5b50\uff1a<\/p>\n<pre config=\"brush:java;toolbar:false;\">package com.yeetrack.test;\n   \nimport java.sql.Connection;\nimport java.sql.DriverManager;\nimport java.sql.SQLException;\nimport java.sql.Statement;\n   \n\/**\n * Created with IntelliJ IDEA.\n * User: youthflies\n * Date: 13-3-7\n * Time: \u4e0a\u534811:43\n * To change this template use File | Settings | File Templates.\n *\/\npublic class TranMysql\n{\n    public static final String DBDRIVER = &quot;com.mysql.jdbc.Driver&quot;;\n    public static final String DBURL = &quot;jdbc:mysql:\/\/127.0.0.1:3306\/test&quot;;\n    public static final String DBUSER = &quot;root&quot;;\n    public static final String DBPASS = &quot;toor&quot;;\n   \n    public static void main(String[] args)\n    {\n        Connection conn = null;\n        Statement stmt = null;\n        try\n        {\n            Class.forName(DBDRIVER);\n            conn = DriverManager.getConnection(DBURL,DBUSER, DBPASS);\n            conn.setAutoCommit(false); \/\/\u53d6\u6d88\u81ea\u52a8\u63d0\u4ea4\n            stmt = conn.createStatement();\n            \/\/\u63d2\u5165\u4e09\u6761\u6570\u636e\n            stmt.addBatch(&quot;insert into User (name, password) values ('youthflies','youthflies')&quot;);\n            stmt.addBatch(&quot;insert into User (name, password) values ('gameace', 'gameace')&quot;);\n            stmt.addBatch(&quot;insert into User (name, password) values ('victorace', 'victorace')&quot;);\n        } catch (ClassNotFoundException e)\n        {\n            e.printStackTrace();  \/\/To change body of catch statement use File | Settings | File Templates.\n        } catch (SQLException e)\n        {\n            e.printStackTrace();  \/\/To change body of catch statement use File | Settings | File Templates.\n        }\n        try\n        {\n            int temp[] = stmt.executeBatch(); \/\/\u6279\u91cf\u6267\u884c\n            for(int i=0;i&lt;=temp.length-1;i++)\n                System.out.println(temp[i]);\n            System.out.println(&quot;\u6267\u884c\u4e86:&quot;+temp.length);\n            conn.commit(); \/\/\u6279\u91cf\u6267\u884c\u6210\u529f\u5c31\u63d0\u4ea4\u4e8b\u52a1\n   \n        } catch (SQLException e)\n        {\n            try\n            {\n                conn.rollback(); \/\/\u6279\u91cf\u6267\u884c\u5931\u8d25\uff0c\u4e8b\u52a1\u56de\u6eda\n            } catch (SQLException e1)\n            {\n                e1.printStackTrace();  \/\/To change body of catch statement use File | Settings | File Templates.\n            }\n            e.printStackTrace();  \/\/To change body of catch statement use File | Settings | File Templates.\n        }\n   \n        try\n        {\n            stmt.close();\n            conn.close();\n        } catch (SQLException e)\n        {\n            e.printStackTrace();  \/\/To change body of catch statement use File | Settings | File Templates.\n        }\n    }\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6570\u636e\u5e93\u4e2d\u7684\u4e8b\u52a1\u5c31\u662f\u4e00\u4e2a\u4e8b\u52a1\u4e2d\u7684\u64cd\u4f5c\u8981\u4e48\u4e00\u8d77\u6210\u529f,\u8981\u4e48\u4e00\u8d77\u5931\u8d25\uff0c\u4e8b\u52a1\u672c\u8eab\u5177\u6709\u539f\u5b50\u6027\u3001\u4e00\u81f4\u6027\u3001\u9694\u79bb\u6027\u548c\u6301\u4e45\u6027\u3002 SET AUTOCOMMIT = 0; &nbsp;\/\/\u53d6\u6d88\u81ea\u52a8\u63d0\u4ea4\uff0c\u5f00\u59cb\u4e8b\u52a1\u5904\u7406<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[33],"tags":[8,7,5],"class_list":["post-23","post","type-post","status-publish","format-standard","hentry","category-coding","tag-java","tag-7","tag-5"],"views":2546,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/23","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=23"}],"version-history":[{"count":1,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/23\/revisions"}],"predecessor-version":[{"id":193,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/23\/revisions\/193"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=23"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=23"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=23"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}