jdbc操作AutoCommit
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestAutoCommit {
public static void main(String[] args) throws Exception {
TestAutoCommit auto=new TestAutoCommit();
Connection conn=auto.getConn();
boolean commit=conn.getAutoCommit();
System.out.println("自動提交: "+commit);
//關閉提交功能
conn.setAutoCommit(false);
System.out.println("自動提交: "+conn.getAutoCommit());
Statement stmt=conn.createStatement();
stmt.execute("insert into student(name,sex,grade) values('xxxxx','m','2008811237')");
stmt.execute("insert into student(name,sex,grade) values('yyyyy','f','2008811219')");
ResultSet rs=stmt.executeQuery("select * from student");
while(rs.next()){
System.out.println("Row: "+rs.getRow()+"\tId: "+rs.getInt(1)+"\tName: "+rs.getString(2)
+"\tSex: "+rs.getString(3)+"\tGrade: "+rs.getString(4));
}
// 提交事務
conn.commit();
System.out.println("-------------------------------------");
rs=stmt.executeQuery("select * from student");
while(rs.next()){
System.out.println("Row: "+rs.getRow()+"\tId: "+rs.getInt(1)+"\tName: "+rs.getString(2)
+"\tSex: "+rs.getString(3)+"\tGrade: "+rs.getString(4));
}
//恢復原來的提交模式
conn.setAutoCommit(commit);
stmt.close();
}
public Connection getConn() {
Connection conn=null;
String url="jdbc:mysql://localhost/dandan?user=root&password=dada";
try {
Class.forName("org.gjt.mm.mysql.Driver");
try {
conn=DriverManager.getConnection(url);
} catch (SQLException e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return conn;
}
}
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestAutoCommit {
public static void main(String[] args) throws Exception {
TestAutoCommit auto=new TestAutoCommit();
Connection conn=auto.getConn();
boolean commit=conn.getAutoCommit();
System.out.println("自動提交: "+commit);
//關閉提交功能
conn.setAutoCommit(false);
System.out.println("自動提交: "+conn.getAutoCommit());
Statement stmt=conn.createStatement();
stmt.execute("insert into student(name,sex,grade) values('xxxxx','m','2008811237')");
stmt.execute("insert into student(name,sex,grade) values('yyyyy','f','2008811219')");
ResultSet rs=stmt.executeQuery("select * from student");
while(rs.next()){
System.out.println("Row: "+rs.getRow()+"\tId: "+rs.getInt(1)+"\tName: "+rs.getString(2)
+"\tSex: "+rs.getString(3)+"\tGrade: "+rs.getString(4));
}
// 提交事務
conn.commit();
System.out.println("-------------------------------------");
rs=stmt.executeQuery("select * from student");
while(rs.next()){
System.out.println("Row: "+rs.getRow()+"\tId: "+rs.getInt(1)+"\tName: "+rs.getString(2)
+"\tSex: "+rs.getString(3)+"\tGrade: "+rs.getString(4));
}
//恢復原來的提交模式
conn.setAutoCommit(commit);
stmt.close();
}
public Connection getConn() {
Connection conn=null;
String url="jdbc:mysql://localhost/dandan?user=root&password=dada";
try {
Class.forName("org.gjt.mm.mysql.Driver");
try {
conn=DriverManager.getConnection(url);
} catch (SQLException e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return conn;
}
}
相關文章
- 聊聊jdbc的batch操作JDBCBAT
- jdbc Statement和PrepareStatement操作JDBCREST
- MySQL 的 autocommitMySqlMIT
- sql mysql variable autocommit (5)MySqlMIT
- mysql 設定禁止autocommitMySqlMIT
- JDBC-MySql基礎操作詳解JDBCMySql
- Spring04——Spring操作JdbcTemplate進行JDBC操作SpringJDBC
- 自動提交(AUTOCOMMIT)的配置MIT
- 練習最原始的JDBC的基本操作JDBC
- select for update與autocommit關係MIT
- InnoDB禁止autocommit預設開啟MIT
- 通過 Spring 框架如何進行JDBC操作呢?Spring框架JDBC
- 對於JDBC資料庫的初始化操作JDBC資料庫
- SQLAlchemy 基礎知識 - autoflush 和 autocommit(轉)SQLMIT
- 不用JDBC:ODBC bridge直接操作Access 資料庫 (轉)JDBC資料庫
- oracle11g sqlplus引數autocommitOracleSQLMIT
- 使用JDBC操作SAP雲平臺上的HANA資料庫JDBC資料庫
- Windows下關閉MySQL的自動提交(autocommit)功能WindowsMySqlMIT
- 【Mybatis原始碼解析】- JDBC連線資料庫的原理和操作MyBatis原始碼JDBC資料庫
- 求救:jdbc與mysql透過Servlet操作後連線關閉不了JDBCMySqlServlet
- JDBCJDBC
- MySQL Study之–MySQL關閉自動commit(autocommit)薦MySqlMIT
- MySQL procedure SET autocommit=0; Error Code: 1064DELIMITER $$MySqlMITError
- 單例模式在JDBC資料庫連線操作裡的應用單例模式JDBC資料庫
- JDBC學習1:詳解JDBC使用JDBC
- JavaWeb——JDBCJavaWebJDBC
- JDBC概述JDBC
- jdbc【oracle】JDBCOracle
- JDBC codeJDBC
- jdbc作用JDBC
- jdbc savePointJDBC
- jdbc batchJDBCBAT
- JDBC differences between the DB2 Universal JDBC Driver and other DB2 JDBC driversJDBCDB2
- Oracle sqlplus引數autocommit(自動提交)的設定OracleSQLMIT
- Java 之 JDBCJavaJDBC
- SpringData JDBCSpringJDBC
- Java之JDBCJavaJDBC
- JDBC詳解JDBC